Skip to content

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

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

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.13bugs and 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