From d975a18fd6aa95b7e9e8b3a85623f27ea803516b Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 25 Nov 2016 21:06:40 +0100 Subject: [PATCH] added doubling of buffer size in checkSectionSize when missing space. Used 1024 instead of 1000 as start size --- .../src/file_sharing/file_sharing_defaults.h | 2 +- libretroshare/src/file_sharing/filelist_io.h | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/file_sharing/file_sharing_defaults.h b/libretroshare/src/file_sharing/file_sharing_defaults.h index 92411a8ca..04cc54b56 100644 --- a/libretroshare/src/file_sharing/file_sharing_defaults.h +++ b/libretroshare/src/file_sharing/file_sharing_defaults.h @@ -54,4 +54,4 @@ static const uint32_t NB_ENTRY_INDEX_BITS = 22 ; // Do not static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer. Depends on the two values just before. Dont change! static const uint32_t DELAY_BEFORE_DROP_REQUEST = 600; // every 10 min -static const uint32_t FL_BASE_TMP_SECTION_SIZE = 1000 ; +static const uint32_t FL_BASE_TMP_SECTION_SIZE = 4096 ; diff --git a/libretroshare/src/file_sharing/filelist_io.h b/libretroshare/src/file_sharing/filelist_io.h index f02d07ed7..0fcdb00fb 100644 --- a/libretroshare/src/file_sharing/filelist_io.h +++ b/libretroshare/src/file_sharing/filelist_io.h @@ -109,13 +109,26 @@ private: static bool checkSectionSize(unsigned char *& buff,uint32_t& buff_size,uint32_t offset,uint32_t S) { + // This tests avoids an infinite loop when growing new size + + if(offset + S + SECTION_HEADER_MAX_SIZE > 0x8fffffff) + return false ; + if(offset + S + SECTION_HEADER_MAX_SIZE > buff_size) { - buff = (unsigned char *)realloc(buff,offset + S + SECTION_HEADER_MAX_SIZE) ; - buff_size = offset + S + SECTION_HEADER_MAX_SIZE; + uint32_t new_size = (buff_size == 0)?512:buff_size ; + + while(new_size < offset + S + SECTION_HEADER_MAX_SIZE) + new_size <<= 1 ; + + buff = (unsigned char *)realloc(buff,new_size) ; if(!buff) + { + buff_size = 0 ; return false ; + } + buff_size = new_size ; } return true ; }