mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
LibCompress: Error on truncated uncompressed DEFLATE blocks
This commit is contained in:
parent
f56b897622
commit
4098335600
2 changed files with 15 additions and 0 deletions
|
@ -95,3 +95,15 @@ TEST_CASE(gzip_round_trip)
|
||||||
EXPECT(!uncompressed.is_error());
|
EXPECT(!uncompressed.is_error());
|
||||||
EXPECT(uncompressed.value() == original);
|
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)
|
if (m_bytes_remaining == 0)
|
||||||
return false;
|
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;
|
Array<u8, 4096> temporary_buffer;
|
||||||
auto readable_bytes = temporary_buffer.span().trim(min(m_bytes_remaining, m_decompressor.m_output_buffer.empty_space()));
|
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));
|
auto read_bytes = TRY(m_decompressor.m_input_stream->read_some(readable_bytes));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue