mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:07:35 +00:00
LibCompress: Use a bit stream for the entire GZIP decompression process
We currently mix normal and bit streams during GZIP decompression, where the latter is a wrapper around the former. This isn't causing issues now as the underlying bit stream buffer is a byte, so the normal stream can pick up where the bit stream left off. In order to increase the size of that buffer though, the normal stream will not be able to assume it can resume reading after the bit stream. The buffer can easily contain more bits than it was meant to read, so when the normal stream resumes, there may be N bits leftover in the bit stream that the normal stream was meant to read. To avoid weird behavior when mixing streams, this changes the GZIP decompressor to always read from a bit stream.
This commit is contained in:
parent
9423662107
commit
20aaab47f9
4 changed files with 12 additions and 11 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <LibCompress/Gzip.h>
|
||||
|
||||
#include <AK/BitStream.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
|
@ -38,9 +39,9 @@ bool BlockHeader::supported_by_implementation() const
|
|||
return true;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<GzipDecompressor::Member>> GzipDecompressor::Member::construct(BlockHeader header, Stream& stream)
|
||||
ErrorOr<NonnullOwnPtr<GzipDecompressor::Member>> GzipDecompressor::Member::construct(BlockHeader header, LittleEndianInputBitStream& stream)
|
||||
{
|
||||
auto deflate_stream = TRY(DeflateDecompressor::construct(MaybeOwned<Stream>(stream)));
|
||||
auto deflate_stream = TRY(DeflateDecompressor::construct(MaybeOwned<LittleEndianInputBitStream>(stream)));
|
||||
return TRY(adopt_nonnull_own_or_enomem(new (nothrow) Member(header, move(deflate_stream))));
|
||||
}
|
||||
|
||||
|
@ -51,7 +52,7 @@ GzipDecompressor::Member::Member(BlockHeader header, NonnullOwnPtr<DeflateDecomp
|
|||
}
|
||||
|
||||
GzipDecompressor::GzipDecompressor(NonnullOwnPtr<Stream> stream)
|
||||
: m_input_stream(move(stream))
|
||||
: m_input_stream(make<LittleEndianInputBitStream>(move(stream)))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue