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