mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47:44 +00:00
LibCompress: Allow partial header reads in GzipDecompressor
We now read the header into a temporary header byte array that is used as the header once its filled up by the input stream, instead of just ending the stream if we are out of bytes mid header.
This commit is contained in:
parent
3dfa3d2d9d
commit
1d8ab74cbf
2 changed files with 11 additions and 3 deletions
|
@ -106,14 +106,20 @@ size_t GzipDecompressor::read(Bytes bytes)
|
|||
|
||||
return nread;
|
||||
} else {
|
||||
BlockHeader header;
|
||||
m_input_stream >> Bytes { &header, sizeof(header) };
|
||||
m_partial_header_offset += m_input_stream.read(Bytes { m_partial_header, sizeof(BlockHeader) }.slice(m_partial_header_offset));
|
||||
|
||||
if (m_input_stream.handle_any_error()) {
|
||||
if (m_input_stream.handle_any_error() || m_input_stream.unreliable_eof()) {
|
||||
m_eof = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (m_partial_header_offset < sizeof(BlockHeader)) {
|
||||
return 0; // partial header read
|
||||
}
|
||||
m_partial_header_offset = 0;
|
||||
|
||||
BlockHeader header = *(reinterpret_cast<BlockHeader*>(m_partial_header));
|
||||
|
||||
if (!header.valid_magic_number() || !header.supported_by_implementation()) {
|
||||
set_fatal_error();
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue