mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:17:35 +00:00
LibCompress: Handle and propagate stream errors in GzipDecompressor
This commit makes read short-circuit if its input stream errored, as well as propagate error handling to wrapped sub streams, similarly to DeflateDecompressor.
This commit is contained in:
parent
ea5f83616e
commit
eb343296ce
2 changed files with 12 additions and 0 deletions
|
@ -78,6 +78,11 @@ size_t GzipDecompressor::read(Bytes bytes)
|
||||||
current_member().m_checksum.update(bytes.trim(nread));
|
current_member().m_checksum.update(bytes.trim(nread));
|
||||||
current_member().m_nread += nread;
|
current_member().m_nread += nread;
|
||||||
|
|
||||||
|
if (current_member().m_stream.handle_any_error()) {
|
||||||
|
set_fatal_error();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (nread < bytes.size()) {
|
if (nread < bytes.size()) {
|
||||||
LittleEndian<u32> crc32, input_size;
|
LittleEndian<u32> crc32, input_size;
|
||||||
m_input_stream >> crc32 >> input_size;
|
m_input_stream >> crc32 >> input_size;
|
||||||
|
@ -188,6 +193,12 @@ Optional<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
|
||||||
|
|
||||||
bool GzipDecompressor::unreliable_eof() const { return m_eof; }
|
bool GzipDecompressor::unreliable_eof() const { return m_eof; }
|
||||||
|
|
||||||
|
bool GzipDecompressor::handle_any_error()
|
||||||
|
{
|
||||||
|
bool handled_errors = m_input_stream.handle_any_error();
|
||||||
|
return Stream::handle_any_error() || handled_errors;
|
||||||
|
}
|
||||||
|
|
||||||
GzipCompressor::GzipCompressor(OutputStream& stream)
|
GzipCompressor::GzipCompressor(OutputStream& stream)
|
||||||
: m_output_stream(stream)
|
: m_output_stream(stream)
|
||||||
{
|
{
|
||||||
|
|
|
@ -67,6 +67,7 @@ public:
|
||||||
bool discard_or_error(size_t) override;
|
bool discard_or_error(size_t) override;
|
||||||
|
|
||||||
bool unreliable_eof() const override;
|
bool unreliable_eof() const override;
|
||||||
|
bool handle_any_error() override;
|
||||||
|
|
||||||
static Optional<ByteBuffer> decompress_all(ReadonlyBytes);
|
static Optional<ByteBuffer> decompress_all(ReadonlyBytes);
|
||||||
static bool is_likely_compressed(ReadonlyBytes bytes);
|
static bool is_likely_compressed(ReadonlyBytes bytes);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue