1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 09:05:09 +00:00

LibCompress: Add another unit test.

I suspected an error in CircularDuplexStream::read(Bytes, size_t). This
does not appear to be the case, this test case is useful regardless.

The following script was used to generate the test:

    import gzip

    uncompressed = []
    for _ in range(0x100):
        uncompressed.append(1)
    for _ in range(0x7e00):
        uncompressed.append(0)
    for _ in range(0x100):
        uncompressed.append(1)

    compressed = gzip.compress(bytes(uncompressed))
    compressed = ", ".join(f"0x{byte:02x}" for byte in compressed)

    print(f"""\
    TEST_CASE(gzip_decompress_repeat_around_buffer)
    {{
        const u8 compressed[] = {{
            {compressed}
        }};

        u8 uncompressed[0x8011];
        Bytes{{ uncompressed, sizeof(uncompressed) }}.fill(0);
        uncompressed[0x8000] = 1;

        const auto decompressed = Compress::GzipDecompressor::decompress_all({{ compressed, sizeof(compressed) }});

        EXPECT(compare({{ uncompressed, sizeof(uncompressed) }}, decompressed.bytes()));
    }}
    """, end="")
This commit is contained in:
asynts 2020-09-05 13:18:01 +02:00 committed by Andreas Kling
parent e2e2e782d4
commit 5d85be7ed4
2 changed files with 23 additions and 3 deletions

View file

@ -78,6 +78,8 @@ size_t GzipDecompressor::read(Bytes bytes)
m_input_stream >> crc32 >> input_size;
if (crc32 != current_member().m_checksum.digest()) {
// FIXME: Somehow the checksum is incorrect?
set_fatal_error();
return 0;
}