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 — `LZMADecompressor.decompress(b'', max_length=0)` raises `LZMAError` on the second consecutive call · Issue #160000 · python/cpython

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

New issue
Copy link
New issue
Copy link
Open
#160205
Open
LZMADecompressor.decompress(b'', max_length=0) raises LZMAError on the second consecutive call#160000
#160205
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@pganssle
pganssle
opened on Oct 21, 2026
Issue body actions

Bug description

Calling decompress with no new input and max_length=0 works once, but a second consecutive such call raises:

>>> import lzma
>>> d = lzma.LZMADecompressor()
>>> d.decompress(b"", max_length=0)
b''
>>> d.decompress(b"", max_length=0)
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    d.decompress(b"", max_length=0)
_lzma.LZMAError: Insufficient buffer space

BZ2Decompressor, zlib._ZlibDecompressor and ZstdDecompressor all return b'' for any number of such calls, and the decompressor stays usable. The same happens after real input, e.g. decompress(stream, 1) followed by two decompress(b'', 0) calls.

max_length=0 is a legitimate request ("just buffer this, don't produce output yet"), so I would expect b'' and no error.

The mechanism, as far as I can tell: liblzma returns LZMA_BUF_ERROR when two consecutive lzma_code calls can make no progress (no input consumed, no output produced). decompress_buf already treats that as benign, but only when there is output space available: Modules/_lzmamodule.c lines 962-964. With max_length=0 the output buffer has zero bytes, so avail_out > 0 is false and the error goes to catch_lzma_error, which maps it to "Insufficient buffer space" (Modules/_lzmamodule.c lines 169-171). Dropping the avail_out > 0 condition when avail_in == 0 is probably enough; zlibmodule.c tolerates Z_BUF_ERROR unconditionally in the equivalent loop.

Found by the Hypothesis tests in #159960, which record it as LZMADecompressorTests.test_repeated_max_length_zero under expectedFailure. Those tests also leave max_length=0 out of the broader lzma strategies for now so that the other properties keep running; that carve-out can go once this is fixed.

CPython versions tested on

CPython main (4e3d5ec), liblzma 5.8.4

Operating systems tested on

Linux

Linked PRs

  • gh-160000: Fix LZMADecompressor raising on repeated empty decompress calls #160205

Activity

  1. pganssle
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 21, 2026
  2. aisk
    added this to Compression issues 🗜on Oct 21, 2026
  3. aisk
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Oct 21, 2026
  4. pganssle
    added a commit that references this issue on Oct 21, 2026

    Add a pinned test for max_length=0 calls with output pending

    e03f55a
  5. bunnysayzz commented on Oct 22, 2026

    @bunnysayzz
    bunnysayzz
    on Oct 22, 2026
    More actions

    Root cause is in Modules/_lzmamodule.c, in decompress_buf. liblzma returns LZMA_BUF_ERROR when two consecutive lzma_code calls make no progress, and the code only treats that as benign when avail_in == 0 and avail_out > 0. With max_length=0 there is no output space, so the second call raises instead of returning b'', and the same happens after real input when output is pending internally and avail_out is 0.

    Fix widens the benign check to 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. Added a regression test in Lib/test/test_lzma.py for both the empty case and the after-real-input case, plus a NEWS entry. Opening the fix PR right after this comment.

  6. pganssle
    added 2 commits that reference this issue on Oct 23, 2026

    Add a pinned test for max_length=0 calls with output pending

    432ac6f

    Pin the known compression bugs as expected-failure examples

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Compression issues 🗜
      Status
      No status
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.