Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd behaviour with zlib.decompressobj optional parameter "wbits" #51440

Closed
pythonhacker mannequin opened this issue Oct 23, 2009 · 4 comments
Closed

Odd behaviour with zlib.decompressobj optional parameter "wbits" #51440

pythonhacker mannequin opened this issue Oct 23, 2009 · 4 comments
Assignees
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@pythonhacker
Copy link
Mannequin

pythonhacker mannequin commented Oct 23, 2009

BPO 7191
Nosy @akuchling, @birkenfeld

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2010-03-01.19:52:14.857>
created_at = <Date 2009-10-23.13:40:56.064>
labels = ['type-bug', 'docs']
title = 'Odd behaviour with zlib.decompressobj optional parameter "wbits"'
updated_at = <Date 2010-03-01.19:52:14.855>
user = 'https://bugs.python.org/pythonhacker'

bugs.python.org fields:

activity = <Date 2010-03-01.19:52:14.855>
actor = 'akuchling'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2010-03-01.19:52:14.857>
closer = 'akuchling'
components = ['Documentation']
creation = <Date 2009-10-23.13:40:56.064>
creator = 'pythonhacker'
dependencies = []
files = []
hgrepos = []
issue_num = 7191
keywords = []
message_count = 4.0
messages = ['94386', '94409', '95161', '100263']
nosy_count = 3.0
nosy_names = ['akuchling', 'georg.brandl', 'pythonhacker']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue7191'
versions = ['Python 3.0']

@pythonhacker
Copy link
Mannequin Author

pythonhacker mannequin commented Oct 23, 2009

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

@pythonhacker pythonhacker mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 23, 2009
@birkenfeld
Copy link
Member

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.

@birkenfeld birkenfeld added docs Documentation in the Doc dir and removed stdlib Python modules in the Lib dir labels Oct 24, 2009
@birkenfeld birkenfeld self-assigned this Oct 24, 2009
@pythonhacker
Copy link
Mannequin Author

pythonhacker mannequin commented Nov 12, 2009

Ok, so you think a documentation update is enough ? Thanks.

@akuchling
Copy link
Member

wbits described further in rev78561. Thanks for your suggestion!

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants