From 89b62d432b08ef8d6d4a3cfcc1013dd1fadb1d7b Mon Sep 17 00:00:00 2001 From: Luke1410 Date: Sat, 2 Jun 2018 21:19:41 +0200 Subject: [PATCH] - add compile time setting to set upper bound for retrieved file sizes (fixes part of #19) --- Source/FileListTransfer.cpp | 5 ++++- Source/RakNetDefines.h | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/FileListTransfer.cpp b/Source/FileListTransfer.cpp index 28dcab500..ecc913908 100644 --- a/Source/FileListTransfer.cpp +++ b/Source/FileListTransfer.cpp @@ -759,7 +759,10 @@ void FileListTransfer::OnReferencePush(Packet *packet, bool isTheFullFile) FLR_MemoryBlock mb; if (fileListReceiver->pushedFiles.Has(onFileStruct.fileIndex)==false) { - mb.flrMemoryBlock=(char*) rakMalloc_Ex(onFileStruct.byteLengthOfThisFile, _FILE_AND_LINE_); + if (onFileStruct.byteLengthOfThisFile <= RAKNET_MAX_RETRIEVABLE_FILESIZE) + mb.flrMemoryBlock=(char*) rakMalloc_Ex(onFileStruct.byteLengthOfThisFile, _FILE_AND_LINE_); + else + mb.flrMemoryBlock = nullptr; fileListReceiver->pushedFiles.SetNew(onFileStruct.fileIndex, mb); } else diff --git a/Source/RakNetDefines.h b/Source/RakNetDefines.h index ea313c551..bf5817f3f 100644 --- a/Source/RakNetDefines.h +++ b/Source/RakNetDefines.h @@ -192,4 +192,12 @@ //#define USE_THREADED_SEND +// Controls the maximum retrievable filesize for incoming files using FileListTransfer. +// The configured limit only applies for files which are transferred incrementally (which basically applies to any larger file). +// Note that this also impacts the upper limit for memory allocations. It's suggested to redefine the value to a reasonable smaller size in the RakNetDefineOverrides.h header file. +// For backwards compatibility with RakNet, the default is set to 4 GiB-1. +#ifndef RAKNET_MAX_RETRIEVABLE_FILESIZE +#define RAKNET_MAX_RETRIEVABLE_FILESIZE (0xFFFFFFFF) +#endif + #endif // __RAKNET_DEFINES_H