mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
LibCompress: Error on truncated uncompressed DEFLATE blocks
This commit is contained in:
parent
f56b897622
commit
4098335600
Notes:
sideshowbarker
2024-07-17 02:08:15 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/4098335600 Pull-request: https://github.com/SerenityOS/serenity/pull/18326 Issue: https://github.com/SerenityOS/serenity/issues/18312
@ -95,3 +95,15 @@ TEST_CASE(gzip_round_trip)
|
||||
EXPECT(!uncompressed.is_error());
|
||||
EXPECT(uncompressed.value() == original);
|
||||
}
|
||||
|
||||
TEST_CASE(gzip_truncated_uncompressed_block)
|
||||
{
|
||||
Array<u8, 38> const compressed {
|
||||
0x1F, 0x8B, 0x08, 0x13, 0x5D, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x1C,
|
||||
0x1C, 0xFF, 0xDB, 0xFB, 0xFF, 0xDB
|
||||
};
|
||||
|
||||
auto const decompressed_or_error = Compress::GzipDecompressor::decompress_all(compressed);
|
||||
EXPECT(decompressed_or_error.is_error());
|
||||
}
|
||||
|
@ -238,6 +238,9 @@ ErrorOr<bool> DeflateDecompressor::UncompressedBlock::try_read_more()
|
||||
if (m_bytes_remaining == 0)
|
||||
return false;
|
||||
|
||||
if (m_decompressor.m_input_stream->is_eof())
|
||||
return Error::from_string_literal("Input data ends in the middle of an uncompressed DEFLATE block");
|
||||
|
||||
Array<u8, 4096> temporary_buffer;
|
||||
auto readable_bytes = temporary_buffer.span().trim(min(m_bytes_remaining, m_decompressor.m_output_buffer.empty_space()));
|
||||
auto read_bytes = TRY(m_decompressor.m_input_stream->read_some(readable_bytes));
|
||||
|
Loading…
Reference in New Issue
Block a user