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: Odd behaviour with zlib.decompressobj optional parameter "wbits"
Type: behavior Stage:
Components: Documentation Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: akuchling, georg.brandl, pythonhacker
Priority: normal Keywords:

Created on 2009-10-23 13:40 by pythonhacker, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg94386 - (view) Author: Anand B Pillai (pythonhacker) * Date: 2009-10-23 13:40
>>> import zlib
>>> help(zlib.decompressobj)
Help on built-in function decompressobj in module zlib:

decompressobj(...)
    decompressobj([wbits]) -- Return a decompressor object.

    Optional arg wbits is the window buffer size.

I experimented with this parameter and by trial and
error found out that it accepts only values from 8 to
15 inclusive. 

>>> z=zlib.decompressobj(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid initialization option
>>> z=zlib.decompressobj(7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid initialization option
>>> z=zlib.decompressobj(16)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid initialization option

>>> z1=zlib.decompressobj(8)
>>> z2=zlib.decompressobj(15)

Now to the odd part. Let us create another decompressobj without any
parameter. 

>>> z3=zlib.decompressobj()

Now compress some data.
>>> c=zlib.compress("This is a medium line of text")

Decompress with z2 works fine.
>>> z3.decompress(c)
b'This is a medium line of text'

Decompress with z2 is also fine.

>>> z2.decompress(c)
b'This is a medium line of text'

However with z1 it fails.
>>> z1.decompress(c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
zlib.error: Error -3 while decompressing: invalid window size

In fact, only the optional value of 15 seems to work 
for wbits, every other legal value (8-14) fails giving
the same error. I tried this with other random strings
with same effect.

Either there is no need to expose this as a parameter
or there could be a bug with how this parameter is used,
which has to be fixed. In either case, documentation
on this parameter has to be improved and legal range
of values should be provided.
msg94409 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-10-24 11:51
The decompressor can't have a window size smaller than the size used to
compress the stream.  Therefore in your case, it can't be smaller than 15.

Still, the docs must be improved, e.g. compressobj() has more parameters
than documented.
msg95161 - (view) Author: Anand B Pillai (pythonhacker) * Date: 2009-11-12 12:45
Ok, so you think a documentation update is enough ? Thanks.
msg100263 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2010-03-01 19:52
wbits described further in rev78561.  Thanks for your suggestion!
History
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51440
2010-03-01 19:52:14akuchlingsetstatus: open -> closed

nosy: + akuchling
messages: + msg100263

resolution: fixed
2009-12-27 20:46:55amaury.forgeotdarclinkissue7581 superseder
2009-11-12 12:45:26pythonhackersetmessages: + msg95161
2009-10-24 11:51:06georg.brandlsetnosy: + georg.brandl
messages: + msg94409

assignee: georg.brandl
components: + Documentation, - Library (Lib)
2009-10-23 13:40:56pythonhackercreate