Repository navigation
Bound DEFLATE block output buffering in decoder - #4
Merged
Merged
Conversation
A single DEFLATE block can expand arbitrarily (RFC 1951 has no per-block maximum), so one highly-compressible block could be fully expanded into the decoder's internal output buffer before the caller had a chance to drain it, allowing memory to grow without bound (libflate issue #90 / PR #92 analogue). - Add MAX_INTERNAL_BUFFER (64 KiB) cap to step_symbol_loop: once unread output reaches the cap the decoder yields (StepOutcome::Yield), preserving the SymbolLoop state (is_final, Huffman decoders, bit position) so decoding resumes on the next feed(). drive() treats Yield as a break and feed returns control so the caller can drain output()/advance(). - Update the deflate/gzip/zlib drain loops to resume after a cap yield and to collect the final block's output before checking is_finished(); previously a resume that finished mid-block truncated the trailing partial block. - Add regression tests: single 8 MiB block does not buffer whole output, and partial-final-block roundtrips for gzip/zlib. All 73 unit tests, integration tests, and doctests pass; clippy and rustfmt are clean. The public streaming API is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bound the streaming DEFLATE decoder's internal output buffer.
A single DEFLATE block can expand arbitrarily (RFC 1951 has no per-block
maximum), so one highly-compressible block was fully expanded into the internal
buffer before control returned to the caller. The decoder now caps the unread
output at ~64 KiB and yields back, resuming from the saved position.
Ref: sile/libflate#92, sile/libflate#90