Conversation
decompress_chunks returned before it called inflate when the input was empty, and returned once the input was consumed even when the output buffer was full. Raw deflate has no trailer, so inflate can consume the last input byte and still hold output. Decompress.decompress(b"", n) and Decompress.flush() then returned nothing, and zlib.decompress with a small bufsize raised "incomplete or truncated stream". Mirror CPython's zlibmodule.c: call inflate for empty input, and call it again while it fills the output buffer. A stream with no pending output answers Z_BUF_ERROR, so an empty input before any compressed data still leaves eof false. Assisted-by: Claude Code:claude-opus-5-5 Fixes RustPython#8907
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: RustPython/RustPython/.coderabbit.yml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe decompression loop now processes empty input to retrieve pending output. It checks output-buffer fullness before treating exhausted input as complete. Rust and Python regression tests cover pending output, small output limits, and incomplete streams. ChangesPending zlib output
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The reviewed change has no identified issue that needs resolution before merge. Normal checks remain appropriate. Architecture SummaryArchitecture risk: 🟡 Medium · up to The change affects 2 systems. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
Reliability and maintainability
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Return when the stream ended, or when the input is used up and inflate left part of the output buffer empty. A full buffer falls through to the existing next iteration, as CPython's loop runs while avail_out is zero, instead of a separate branch ahead of the exit check. Assisted-by: Claude Code:claude-opus-5-5
|
Human review by me. First impl was using a continue: if produced == additional && !stream_end {
// A full output buffer can leave output pending in
// inflate, even with no input left.
continue 'outer;
}IMHO it was correct but |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
| // Empty input still reaches inflate, like CPython: inflate can hold output | ||
| // after it consumed the last input byte. A stream with no pending output | ||
| // answers `BufError`, not `StreamEnd`, so `eof` stays false. |
There was a problem hiding this comment.
| // Empty input still reaches inflate, like CPython: inflate can hold output | |
| // after it consumed the last input byte. A stream with no pending output | |
| // answers `BufError`, not `StreamEnd`, so `eof` stays false. |
these comments will look weird after patch
There was a problem hiding this comment.
Done in b39f875: the comment is gone. zlib unit tests: 19 passed.
🤖 Written by Claude Code (2.1.283) using model claude-opus-5-5
Assisted-by: Claude Code:claude-opus-5-5
youknowone
left a comment
There was a problem hiding this comment.
looks good now. please rebase it to upstream.
please also check the changes in details yourself.
thanks!
Fixes #8907.
decompress_chunks(crates/common/src/compression/zlib.rs) returned before it called inflate when the input was empty, and returned once the input was consumed even when the output buffer was full. Raw deflate has no trailer, so inflate can consume the last input byte and still hold output.Decompress.decompress(b"", n)andDecompress.flush()then returned nothing, andzlib.decompress(raw, -15, bufsize)with a smallbufsizeraised "incomplete or truncated stream".This mirrors CPython's
zlibmodule.c: inflate runs for empty input, and runs again while it fills the output buffer. A stream with no pending output answersZ_BUF_ERROR, so an empty input or aflush()before any compressed data still leaveseoffalse (empty_input_does_not_finish_a_streamstill passes;empty_flush_does_not_finish_a_streamis new). After a stream error,decompress(b"")now raises again, as CPython does.Tests
empty_input_returns_pending_output,flush_returns_pending_output,small_bufsize_returns_pending_output,empty_flush_does_not_finish_a_stream(the first three fail before the change).extra_tests/snippets/stdlib_zlib.pywith the reproducer fromzlib.decompressobj:decompress(b"", n)andflush()never return output that inflate still holds (raw deflate loses its last bytes undermax_length) #8907; they pass on RustPython and on CPython 3.13.5.rustpython-common: 135 passed; workspace: 1337 passed, 0 failed.test_zlib+test_gzip: 151 run, 4 skipped, 0 failed, before and after.test_tarfile+test_zipfile+test_shutil: 1360 run, 197 skipped, before and after.cargo fmt --checkand clippy onrustpython-commonare clean.#8908 (#8906) edits the same file and also appends tests at the end of
mod tests; whichever merges second needs a trivial rebase.AI assistance
This change was written with Claude Code (commit trailer
Assisted-by: Claude Code:claude-opus-5-5). It is opened as a draft until a human has verified it, per the AI policy.🤖 Written by Claude Code (2.1.283) using model claude-opus-5-5
Summary by CodeRabbit
flush().