mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-09 18:16:09 +03: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
Notes:
sideshowbarker
2024-07-18 21:17:39 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/1d8ab74cbf9 Pull-request: https://github.com/SerenityOS/serenity/pull/5821
@ -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;
|
||||
|
@ -91,6 +91,8 @@ private:
|
||||
Member& current_member() { return m_current_member.value(); }
|
||||
|
||||
InputStream& m_input_stream;
|
||||
u8 m_partial_header[sizeof(BlockHeader)];
|
||||
size_t m_partial_header_offset { 0 };
|
||||
Optional<Member> m_current_member;
|
||||
|
||||
bool m_eof { false };
|
||||
|
Loading…
Reference in New Issue
Block a user