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
The test
test_decompress_unconsumed_tail_after_eof(added in gh-158169 / #158177) fails on main:Reproducer:
Root cause:
Commit 8122ff4 (gh-158169) added this line to
save_unconsumed_input()inModules/zlibmodule.c:This advances
next_inpast the leftover input. The following block then computes:Since
next_inwas already advanced,left_sizeis computed incorrectly, sounconsumed_tailis not cleared at end of stream.Linked PRs