Skip to content

zlib.Decompress.unconsumed_tail not cleared at end of stream (regression from gh-158169) #158398

Closed as not planned

Description

@Tony123-tech

The test test_decompress_unconsumed_tail_after_eof (added in gh-158169 / #158177) fails on main:

FAIL: test_decompress_unconsumed_tail_after_eof
AssertionError: b'0123456789' != b''

Reproducer:

import zlib

source = b'abcdefghijklmnopqrstuvwxyz'
remainder = b'0123456789'
dco = zlib.decompressobj()
data = dco.decompress(zlib.compress(source) + remainder, 1)
data += dco.decompress(dco.unconsumed_tail)

assert dco.eof
assert data == source
assert dco.unconsumed_tail == b''
assert dco.unused_data == remainder

Root cause:

Commit 8122ff4 (gh-158169) added this line to save_unconsumed_input() in Modules/zlibmodule.c:

    self->zst.next_in += left_size;

This advances next_in past the leftover input. The following block then computes:

    Py_ssize_t left_size = (Byte *)data->buf + data->len - self->zst.next_in;

Since next_in was already advanced, left_size is computed incorrectly, so unconsumed_tail is not cleared at end of stream.

Linked PRs

Activity

  1. picnixz commented on Sep 29, 2026

    @picnixz
    Member
  2. added
    type-bugAn unexpected behavior, bug, or error
    3.13only security fixes
    3.14bugs and security fixes
    3.16new features, bugs and security fixes
    on Sep 29, 2026
  3. picnixz commented on Sep 29, 2026

    @picnixz
    Member

    3.15 is not affected because backport was not yet merged.

  4. hugovk commented on Sep 29, 2026

    @hugovk
    Member

    The reproducer and test both pass with no error for me on macOS with latest main, and the CI and buildbots are green.

    @Tony123-tech How did you run this? On what OS? How did you build?

  5. added
    pendingThe issue will be closed if no feedback is provided
    on Sep 29, 2026
  6. Tony123-tech commented on Sep 29, 2026

    @Tony123-tech
    ContributorAuthor

    Thanks for checking. I'll re-test on latest main tomorrow and report back with my exact commit, OS, and build steps.

  7. picnixz commented on Sep 29, 2026

    @picnixz
    Member

    I guess the agent was at the wrong main? or something was wrong? I closed the PR because it was likely automated and there was no answer to Hugo's question. We need this answer before your PR. And please, don't use LLMs without checking what they tell you back. They can easily be get out-of-sync (forgot to pull main for instance)

  8. StanFromIreland commented on Sep 29, 2026

    @StanFromIreland
    Member

    I'm closing this for now, I don't see how this could occur (on any platform), I presume the build didn't include the fix.

    Please let us know if that's incorrect, and I will re-open.

  9. Tony123-tech commented on Sep 30, 2026

    @Tony123-tech
    ContributorAuthor

    You're right — I was testing on an older local main (421c411).
    It passes on upstream/main (77c0675). Sorry for the noise.

  10. hosu3das20s05s commented on Sep 30, 2026

    @hosu3das20s05s
  11. zzffeggs commented on Sep 30, 2026

    @zzffeggs
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

    3.13only security fixes3.14bugs and security fixes3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirpendingThe issue will be closed if no feedback is providedtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions