[New-bugs-announce] [issue7191] Odd behaviour with zlib.decompressobj optional parameter "wbits"

Anand B Pillai report at bugs.python.org
Fri Oct 23 15:40:57 CEST 2009


New submission from Anand B Pillai <abpillai at gmail.com>:

>>> 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.

----------
components: Library (Lib)
messages: 94386
nosy: pythonhacker
severity: normal
status: open
title: Odd behaviour with zlib.decompressobj optional parameter "wbits"
type: behavior
versions: Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7191>
_______________________________________


More information about the New-bugs-announce mailing list