1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

LibCompress: Handle literal only lz77 streams in DeflateCompressor

Very incompressible data could sometimes produce no backreferences
which would result in no distance huffman code being created (as it
was not needed), so VERIFY the code exists only if it is actually
needed for writing the stream.
This commit is contained in:
Idan Horowitz 2021-03-14 11:43:18 +02:00 committed by Andreas Kling
parent 1db943e146
commit 7e587a615e
3 changed files with 16 additions and 8 deletions

View file

@ -168,6 +168,14 @@ TEST_CASE(deflate_round_trip_compress_large)
EXPECT(uncompressed.value() == original);
}
TEST_CASE(deflate_compress_literals)
{
// This byte array is known to not produce any back references with our lz77 implementation even at the highest compression settings
Array<u8, 0x13> test { 0, 0, 0, 0, 0x72, 0, 0, 0xee, 0, 0, 0, 0x26, 0, 0, 0, 0x28, 0, 0, 0x72 };
auto compressed = Compress::DeflateCompressor::compress_all(test, Compress::DeflateCompressor::CompressionLevel::GOOD);
EXPECT(compressed.has_value());
}
TEST_CASE(zlib_decompress_simple)
{
const Array<u8, 40> compressed {