This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unconsumed_tail of zlib.Decompress is not always cleared on decompress() call
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nadeem.vawda Nosy List: Takeshi.Yoshino, jcea, nadeem.vawda, python-dev
Priority: normal Keywords:

Created on 2011-05-10 10:44 by Takeshi.Yoshino, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg135697 - (view) Author: Takeshi Yoshino (Takeshi.Yoshino) Date: 2011-05-10 10:44
http://docs.python.org/library/zlib.html
says
"If max_length is not supplied then the whole input is decompressed, and unconsumed_tail is an empty string."

However, if there's preceding decompress call with max_length specified, unconsumed_tail will not be empty.

----
import zlib

c = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -zlib.MAX_WBITS)
compressed = c.compress('abc')
compressed += c.flush(zlib.Z_SYNC_FLUSH)

d = zlib.decompressobj(-zlib.MAX_WBITS)
original = d.decompress(data, 1)
original += d.decompress(d.unconsumed_tail)
print "%r" % d.unconsumed_tail
----

Result is

----
'\x06\x00\x00\x00\xff\xff'
----

Document or code should be fixed.
msg135723 - (view) Author: Nadeem Vawda (nadeem.vawda) * (Python committer) Date: 2011-05-10 17:42
Thanks for the bug report. It seems that the code needs fixing. I'll look
into it this weekend.
msg135970 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-14 12:21
New changeset 6a45567c7245 by Nadeem Vawda in branch '3.1':
Issue #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
http://hg.python.org/cpython/rev/6a45567c7245

New changeset 49c998a88777 by Nadeem Vawda in branch '3.2':
Merge: #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
http://hg.python.org/cpython/rev/49c998a88777

New changeset 088e5d705171 by Nadeem Vawda in branch 'default':
Merge: #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
http://hg.python.org/cpython/rev/088e5d705171
msg135971 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-14 12:29
New changeset 24543f7a87ce by Nadeem Vawda in branch '2.7':
Issue #12050: zlib.decompressobj().decompress() now clears the unconsumed_tail
http://hg.python.org/cpython/rev/24543f7a87ce
msg135972 - (view) Author: Nadeem Vawda (nadeem.vawda) * (Python committer) Date: 2011-05-14 12:36
The code has been fixed. Once again, thanks for the bug report.
msg136141 - (view) Author: Takeshi Yoshino (Takeshi.Yoshino) Date: 2011-05-17 04:33
Thank you for the fix!
History
Date User Action Args
2022-04-11 14:57:17adminsetgithub: 56259
2011-05-17 04:33:06Takeshi.Yoshinosetmessages: + msg136141
2011-05-14 12:36:38nadeem.vawdasetstatus: open -> closed
resolution: fixed
messages: + msg135972

stage: needs patch -> resolved
2011-05-14 12:29:57python-devsetmessages: + msg135971
2011-05-14 12:21:43python-devsetnosy: + python-dev
messages: + msg135970
2011-05-11 19:27:20jceasetnosy: + jcea
2011-05-10 17:42:30nadeem.vawdasetversions: + Python 3.1, Python 2.7, Python 3.2, Python 3.3, - Python 2.6
nosy: + nadeem.vawda

messages: + msg135723

assignee: nadeem.vawda
stage: needs patch
2011-05-10 10:44:13Takeshi.Yoshinocreate