GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-160000: Fix LZMADecompressor raising on repeated empty decompress calls by bunnysayzz · Pull Request #160205 · python/cpython

Conversation

@bunnysayzz

@bunnysayzz bunnysayzz commented Oct 22, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Fixes #160000.

LZMADecompressor.decompress(b'', max_length=0) works once, then raises LZMAError: Insufficient buffer space on the second call. Same after real input when output is pending internally.

In Modules/_lzmamodule.c, decompress_buf treats LZMA_BUF_ERROR from liblzma as benign only when avail_in == 0 and avail_out > 0. With max_length=0 there is no output space, so that check never fires for the empty call, and the error escapes. The fix treats it as benign when avail_in == 0 or avail_out == 0. That is safe because the avail_out == 0 branch either breaks once the requested length is reached or grows the buffer, so it cannot spin.

Also adds a regression test in Lib/test/test_lzma.py covering the empty case and the after-real-input case, and a NEWS entry.

Verified by building CPython from main and running the test suite: test_lzma passes (125 tests), the issue repro returns b'' on repeated calls, the decompressor stays usable afterwards, and corrupt input still raises LZMAError.

Note: this is my first CPython PR, I will complete the CLA check when prompted.

  • Issue: LZMADecompressor.decompress(b'', max_length=0) raises LZMAError on the second consecutive call #160000

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bunnysayzz
pythongh-160000: Fix LZMADecompressor raising on repeated empty decom…
d43200c
…press calls
@python-cla-bot

python-cla-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

  • [email protected]

CLA not signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot mentioned this pull request Oct 22, 2026
LZMADecompressor.decompress(b'', max_length=0) raises LZMAError on the second consecutive call #160000
Open
@bedevere-app bedevere-app Bot added the awaiting review label Oct 22, 2026
pganssle
pganssle reviewed Oct 22, 2026
View reviewed changes
Comment thread Lib/test/test_lzma.py
lzd = LZMADecompressor()
for _ in range(3):
self.assertEqual(lzd.decompress(b'', max_length=0), b'')
# Same after real input: one byte out, then empty calls,

@pganssle pganssle Oct 22, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be split into separate tests or parameterized in some way.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
emmatyping
emmatyping reviewed Oct 23, 2026
View reviewed changes
Comment thread Modules/_lzmamodule.c
Comment on lines +962 to 964
if (lzret == LZMA_BUF_ERROR &&
(lzs->avail_in == 0 || lzs->avail_out == 0)) {
lzret = LZMA_OK; /* That wasn't a real error */

@emmatyping emmatyping Oct 23, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than ignoring the error, we should add the input bytes to the input buffer, then return empty bytes without calling the library.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
emmatyping
emmatyping reviewed Oct 23, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2026-10-22-10-55-00.gh-issue-160000.a1b2c3.rst
Comment on lines +1 to +2
Fix :class:`lzma.LZMADecompressor` raising :exc:`LZMAError` on repeated
``decompress(b'', max_length=0)`` calls.

@emmatyping emmatyping Oct 23, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fix :class:`lzma.LZMADecompressor` raising :exc:`LZMAError` on repeated
``decompress(b'', max_length=0)`` calls.
Fix :class:`lzma.LZMADecompressor` raising :exc:`LZMAError` on repeated
``decompress()`` calls with ``max_length=0``.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@emmatyping emmatyping mentioned this pull request Oct 23, 2026
gh-160121: Correct repeated calls to decompress() with max_length=0 #160517
Open
@emmatyping

emmatyping commented Oct 30, 2026

Copy link
Copy Markdown
Member

@bunnysayzz if you resolve the review comments, I'd be happy to take another look at this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pganssle pganssle pganssle left review comments
@emmatyping emmatyping emmatyping left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

LZMADecompressor.decompress(b'', max_length=0) raises LZMAError on the second consecutive call

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@bunnysayzz @emmatyping @pganssle
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.