diff options
-rw-r--r-- | src/huffman/huff.cpp | 12 | ||||
-rw-r--r-- | src/huffman/huff.h | 2 | ||||
-rw-r--r-- | test/StormTest.cpp | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/src/huffman/huff.cpp b/src/huffman/huff.cpp index 877a294..9de5acb 100644 --- a/src/huffman/huff.cpp +++ b/src/huffman/huff.cpp @@ -517,7 +517,7 @@ unsigned int THuffmannTree::FixupItemPosByWeight(THTreeItem * pNewItem, unsigned } // Builds Huffman tree. Called with the first 8 bits loaded from input stream -void THuffmannTree::BuildTree(unsigned int CompressionType) +bool THuffmannTree::BuildTree(unsigned int CompressionType) { THTreeItem * pNewItem; THTreeItem * pChildLo; @@ -530,7 +530,8 @@ void THuffmannTree::BuildTree(unsigned int CompressionType) MaxWeight = 0; // Ensure that the compression type is in range - assert((CompressionType & 0x0F) <= 0x08); + if((CompressionType & 0x0F) > 0x08) + return false; WeightTable = WeightTables[CompressionType & 0x0F]; // Build the linear list of entries that is sorted by byte weight @@ -581,6 +582,7 @@ void THuffmannTree::BuildTree(unsigned int CompressionType) // Initialize the MinValidValue to 1, which invalidates all quick-link items MinValidValue = 1; + return true; } void THuffmannTree::IncWeightsAndRebalance(THTreeItem * pItem) @@ -765,7 +767,8 @@ unsigned int THuffmannTree::Compress(TOutputStream * os, void * pvInBuffer, int unsigned char * pbOutBuff = os->pbOutBuffer; unsigned char InputByte; - BuildTree(CompressionType); + if(!BuildTree(CompressionType)) + return 0; bIsCmp0 = (CompressionType == 0); // Store the compression type into output buffer @@ -832,7 +835,8 @@ unsigned int THuffmannTree::Decompress(void * pvOutBuffer, unsigned int cbOutLen bIsCmp0 = (CompressionType == 0) ? 1 : 0; // Build the Huffman tree - BuildTree(CompressionType); + if(!BuildTree(CompressionType)) + return 0; // Process the entire input buffer until end of the stream while((DecompressedValue = DecodeOneByte(is)) != 0x100) diff --git a/src/huffman/huff.h b/src/huffman/huff.h index 2bd5abc..89993fd 100644 --- a/src/huffman/huff.h +++ b/src/huffman/huff.h @@ -115,7 +115,7 @@ class THuffmannTree THTreeItem * CreateNewItem(unsigned int DecompressedValue, unsigned int Weight, TInsertPoint InsertPoint); unsigned int FixupItemPosByWeight(THTreeItem * pItem, unsigned int MaxWeight); - void BuildTree(unsigned int CompressionType); + bool BuildTree(unsigned int CompressionType); void IncWeightsAndRebalance(THTreeItem * pItem); void InsertNewBranchAndRebalance(unsigned int Value1, unsigned int Value2); diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 16d8ba2..5dae52a 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -3583,6 +3583,8 @@ static int TestCreateArchive_NonStdNames(const char * szPlainName) AddFileToMpq(&Logger, hMpq, "\x10\x11\x12\x13\\\x14\x15\x16\x17\\\x18\x19\x1a\x1b\\\x1c\x1D\x1E\x1F.txt", "This is the file data 016.", MPQ_FILE_COMPRESS);
AddFileToMpq(&Logger, hMpq, "\x09\x20\x09\x20\\\x20\x09\x20\x09\\\x09\x20\x09\x20\\\x20\x09\x20\x09.txt", "This is the file data 017.", MPQ_FILE_COMPRESS);
AddFileToMpq(&Logger, hMpq, "\x80\x91\xA2\xB3\\\xC4\xD5\xE6\xF7\\\x80\x91\xA2\xB3.txt", "This is the file data 018.", MPQ_FILE_COMPRESS);
+ AddFileToMpq(&Logger, hMpq, "Dir1\x20\x09\x20\\Dir2\x20\x09\x20\\File.txt\x09\x09\x20\x2e", "This is the file data 019.", MPQ_FILE_COMPRESS);
+ AddFileToMpq(&Logger, hMpq, "Dir1\x20\x09\x20\\Dir2\x20\x09\x20\\\x09\x20\x2e\x09\x20\x2e", "This is the file data 020.", MPQ_FILE_COMPRESS);
SFileCloseArchive(hMpq);
}
|