Title: lzma: treat empty input as a no-op, not end of stream by hyoinandout · Pull Request #8752 · RustPython/RustPython · GitHub
Open Graph Title: lzma: treat empty input as a no-op, not end of stream by hyoinandout · Pull Request #8752 · RustPython/RustPython
X Title: lzma: treat empty input as a no-op, not end of stream by hyoinandout · Pull Request #8752 · RustPython/RustPython
Description: Closes #8637 One of checkbox below must be checked. I did not use AI to write the code of this patch. This PR follows our AI policy Summary LZMADecompressor.decompress(b"") finished the decompressor instead of doing nothing. decompress_chunks returns whether the codec signalled LZMA_STREAM_END, and it short-circuits when the chunker has nothing left to feed. That early return answered "the stream ended" for the case where no input was supplied at all — an empty hand, not an empty stream. The caller latches that answer with self.eof |= stream_end, which only ever flips eof on. A single empty call therefore finished the object for good: needs_input went false and every later call was rejected by the if self.eof guard with EOFError, before a single compressed byte had been seen. import lzma blob = lzma.compress(b"data") d = lzma.LZMADecompressor() d.decompress(b"") # d.eof was True / needs_input False, now False / True d.decompress(blob) # was EOFError: End of stream already reached, now b'data' The zlib engine returns false from the identical short-circuit in compression/zlib.rs; lzma had drifted away from it, and this puts the two back in agreement. On the bz2 half of the issue: BZ2Decompressor was fixed incidentally by #8638, which moved the bz2 engine into crates/common. I confirmed current main already matches CPython there, so this PR adds only a regression test for bz2 and no behaviour change. Testing Run on macOS arm64 (aarch64-apple-darwin) against a local CPython 3.14.7. The script from the issue now prints the documented False True / b'data' for both decompressors, matching CPython exactly. Lib/test/test_lzma.py::test_decompressor_chunks_empty — this is precisely the reported scenario, and it was marked expectedFailure with this very EOFError. Marker removed. I re-checked by reverting only the one-line engine change and rebuilding: the test fails with EOFError: End of stream already reached at test_lzma.py:152, and passes with the change, so it genuinely pins the regression rather than riding along. empty_input_does_not_finish_a_stream — new engine unit test, named after the zlib test that already existed and mirrored into bz2, so all three engines stay pinned to the same behaviour instead of drifting apart again. test_lzma — 121 run, 1 skipped, SUCCESS test_bz2, test_zlib, test_gzip, test_tarfile — 1009 run, 113 skipped, SUCCESS cargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --exclude rustpython-capi — clean cargo fmt --check — clean cargo clippy -p rustpython-common --all-features --all-targets -- -D warnings — clean One note on the capi suite, which AGENTS.md also asks for: cargo test in crates/capi dies with SIGSEGV on abstract_::iter::tests::next_item. I verified it crashes identically on unmodified main (2006c63) with this change stashed, so it is pre-existing and unrelated. Not verified on Linux or Windows; the change is platform-independent control flow with no cfg-gated paths. AI disclosure Per the AI policy, this patch was written with AI assistance (Claude Code, model claude-opus-5); the commit carries an Assisted-by: trailer. I reviewed the change, and the CPython comparison, the fails-without-the-fix check, and the test and lint runs above were all executed locally on real hardware. Summary by CodeRabbit Bug Fixes Empty decompression calls no longer incorrectly mark BZ2 or LZMA streams as complete. Compressed data supplied after an empty input is now processed correctly, producing the expected output and end-of-stream status.
Open Graph Description: Closes #8637 One of checkbox below must be checked. I did not use AI to write the code of this patch. This PR follows our AI policy Summary LZMADecompressor.decompress(b"") finished ...
X Description: Closes #8637 One of checkbox below must be checked. I did not use AI to write the code of this patch. This PR follows our AI policy Summary LZMADecompressor.decompress(b"") f...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8752
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:996c2877-4320-8597-babb-c23f2093f64d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D718:DB09F:39DDB8F:49D882A:6B02086A |
| html-safe-nonce | 2a07393c80f731ddc6e49270af36c50b216d49441d364f0b193959e632dad392 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzE4OkRCMDlGOjM5RERCOEY6NDlEODgyQTo2QjAyMDg2QSIsInZpc2l0b3JfaWQiOiI4MTQ4MTIwNDE3NjgxNDEwMTU0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e0fd5041c23349e30ef06cada1905cf3adad41db1eef0a9ab9cdf4b65e6d69e2 |
| hovercard-subject-tag | pull_request:4582799185 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/8752/files |
| twitter:image | https://avatars.githubusercontent.com/u/68385607?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/68385607?s=400&v=4 |
| og:image:alt | Closes #8637 One of checkbox below must be checked. I did not use AI to write the code of this patch. This PR follows our AI policy Summary LZMADecompressor.decompress(b"") finished ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width