File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,15 +38,29 @@ tSharedBuffer cResources::fileGet( std::string pFilename ) {
3838}
3939
4040tSharedBuffer cResources::fileDeRNC (tSharedBuffer pBuffer) {
41+ constexpr uint32 RNCHeaderSize = 18 ;
42+ constexpr uint32 MaxUnpackedSize = 64 * 1024 * 1024 ;
43+
44+ if (pBuffer->size () < RNCHeaderSize)
45+ return pBuffer;
46+
4147 uint32 Header = readBEDWord (pBuffer->data ());
4248 if (Header != ' RNC\01 ' )
4349 return pBuffer;
4450
4551 uint32 Size = readBEDWord (pBuffer->data () + 4 );
52+ uint32 PackedSize = readBEDWord (pBuffer->data () + 8 );
53+
54+ if ((PackedSize > (pBuffer->size () - RNCHeaderSize)) || !Size || (Size > MaxUnpackedSize))
55+ return pBuffer;
4656
4757 auto Unpacked = std::make_shared<std::vector<uint8>>();
4858 Unpacked->resize (Size);
49- rnc_unpack (pBuffer->data (), Unpacked->data ());
59+
60+ long Result = rnc_unpack (pBuffer->data (), Unpacked->data ());
61+ if (Result != static_cast <long >(Size))
62+ return pBuffer;
63+
5064 return Unpacked;
5165}
5266
You can’t perform that action at this time.
0 commit comments