From a8782f0612ae7ea58af95626f5d0545988c44225 Mon Sep 17 00:00:00 2001 From: Phenom Date: Fri, 18 Nov 2016 23:04:32 +0100 Subject: [PATCH] Fix Crash when checking a big-big file storage. After check lot of file with errors, error_string become to big and RS crash. --- .../src/file_sharing/dir_hierarchy.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/file_sharing/dir_hierarchy.cc b/libretroshare/src/file_sharing/dir_hierarchy.cc index 45ebbe0fa..ec89a8dae 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.cc +++ b/libretroshare/src/file_sharing/dir_hierarchy.cc @@ -784,6 +784,12 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co // recurs go through all entries, check that all error_string = ""; + bool bDirOut = false; + bool bDirDouble = false; + bool bFileOut = false; + bool bFileDouble = false; + bool bOrphean = false; + std::vector hits(mNodes.size(),0) ; // count hits of children. Should be 1 for all in the end. Otherwise there's an error. hits[0] = 1 ; // because 0 is never the child of anyone @@ -799,13 +805,13 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co { if(de.subdirs[j] >= mNodes.size()) { - error_string += " - Node child dir out of tab!" ; + if(!bDirOut){ error_string += " - Node child dir out of tab!"; bDirOut = true;} de.subdirs[j] = de.subdirs.back() ; de.subdirs.pop_back(); } else if(hits[de.subdirs[j]] != 0) { - error_string += " - Double hit on a single node dir." ; + if(!bDirDouble){ error_string += " - Double hit on a single node dir."; bDirDouble = true;} de.subdirs[j] = de.subdirs.back() ; de.subdirs.pop_back(); } @@ -819,13 +825,13 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co { if(de.subfiles[j] >= mNodes.size()) { - error_string += " - Node child file out of tab!" ; + if(!bFileOut){ error_string += " - Node child file out of tab!"; bFileOut = true;} de.subfiles[j] = de.subfiles.back() ; de.subfiles.pop_back(); } else if(hits[de.subfiles[j]] != 0) { - error_string += " - Double hit on a single node file." ; + if(!bFileDouble){ error_string += " - Double hit on a single node file."; bFileDouble = true;} de.subfiles[j] = de.subfiles.back() ; de.subfiles.pop_back(); } @@ -836,13 +842,13 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co } } } - else if(mNodes[i] == NULL) + else if( mNodes[i] == NULL ) mFreeNodes.push_back(i) ; for(uint32_t i=0;i