Fix lzw decoding stopping short of full decode

When the required amount of data was just a tiny bit larger than full a
page size (one buffer increment), the decoder would stop since all
compressed data had been read. However, the lzw decoder contains a small
internal bit buffer for code decoding. That is, some remaining bytes had
been retained and were still left to be decoded.
This commit is contained in:
Andreas Molzer committed 2020-12-05 14:57:28 +01:00
1 parent 8ab9d30eff
commit 4d8c64bf1e
3 files changed
+44 -9

No files matched your search

+3 -2
View File
@@ -267,10 +267,11 @@ impl LZWReader {
let mut uncompressed = Vec::with_capacity(max_uncompressed_length);
let mut decoder = weezl::decode::Decoder::with_tiff_size_switch(weezl::BitOrder::Msb, 8);
let mut bytes_read = 0;
while bytes_read < compressed_length && uncompressed.len() < max_uncompressed_length {
while uncompressed.len() < max_uncompressed_length {
let bytes_written = uncompressed.len();
uncompressed.reserve(1 << 12);
let buffer_space = uncompressed.capacity();
let buffer_space = uncompressed.capacity().min(max_uncompressed_length);
uncompressed.resize(buffer_space, 0u8);
let result = decoder.decode_bytes(