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: test_zlib fails with zlib 1.2.4
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: Arfrever, amaury.forgeotdarc, arekm, michael.foord, ncoghlan, pioto, pitrou, r.david.murray, valerio.turturici
Priority: normal Keywords: easy, patch

Created on 2010-03-21 19:12 by arekm, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
8193.patch valerio.turturici, 2010-04-01 08:08
Messages (27)
msg101445 - (view) Author: Arkadiusz Miśkiewicz (arekm) Date: 2010-03-21 19:12
Starting with zlib 1.2.4 zlib test suite fails with:

test test_zlib failed -- Traceback (most recent call last):
  File "/home/users/arekm/rpm/BUILD/Python-2.6.5/Lib/test/test_zlib.py", line 84, in test_baddecompressobj
    self.assertRaises(ValueError, zlib.decompressobj, 0)
AssertionError: ValueError not raised
msg101751 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-03-26 14:54
According to http://www.zlib.net/ChangeLog.txt, since zlib 1.2.3.5::
    - Use zlib header window size if windowBits is 0 in inflateInit2()

The failing test should be changed, for example::
    self.assertRaises(ValueError, zlib.decompressobj, -1)
msg101908 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-29 22:28
I can pick up this bug.
msg101909 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-29 23:09
I confirm that the bug still exists on trunk.
msg101910 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-30 00:02
This is my first patch, i apologize if i make some mistakes.
msg101911 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-03-30 01:08
I imagine the problem exists in 3.x as well (unless someone proves otherwise), so I'm adjusting the versions to the places it can be fixed.

Does the patched test still work with the older zlib?
msg101922 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-30 09:01
Now i make patches for other versions of Python. 
How i try if the patched test still work with the older zlib?
msg101923 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-03-30 09:10
I'm not sure simply changing the value is the right thing to do - with older zlib versions (which do the wrong thing with 0), we definitely want that exception to be triggered.

For newer versions, we want to check that passing in 0 worked as specified in the zlib patch note and that -1 still raises the exception.

Changing the test behaviour based on zlib.ZLIB_VERSION is likely the best option.
msg101924 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-30 09:24
Seems that from Python 2.6 to 3.2 the test work fine. With -1 still raises the exception. By the way, the original problem of Arkadiusz was with Python 2.5.
msg101925 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-30 09:32
The original test, with 0, pass in all versions of Python, from 2.6 to 3.2.
msg101933 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-30 11:32
I try again and ValueError not raised. The test pass without problem, both Python 2.6 and next.
msg101934 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-30 11:33
P.S: the value it's default, 0.
msg102000 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-03-31 12:09
Nick's point is that we should be testing both the value 0 and the value -1, but that we should expect 0 to fail only if zlib.ZLIB_VERSION is less than 1.2.4.  So you'll need to update your patch to keep the 0 test but put it inside an appropriate conditional.

The original problem may be in 2.5, but we are doing security updates only for 2.5, so the fix won't backported to 2.5.  (At least not by us, distributors are of course free to patch their own distributions of earlier python versions.)

I'm not sure what your last comment about the default means.
msg102003 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-31 13:18
This was clear. Now i make a new patch and then upload it.
msg102009 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-31 13:57
Here's the new patch. It's ok?
msg102010 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-03-31 13:58
Looks good to me.
msg102012 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-03-31 14:38
Shouldn't it be
  zlib.ZLIB_VERSION < '1.2.4'
rather than
  zlib.ZLIB_VERSION <= '1.2.4'
?
msg102014 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-03-31 15:16
Are we safe using string comparison here?  How likely is zlib to get into double digit release numbers?  (Too bad the version comparison stuff Tarek is working on isn't already available.)
msg102015 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-03-31 15:21
Note that the exact version which changed the behavior is 1.2.3.5, see http://www.zlib.net/ChangeLog.txt
    - Use zlib header window size if windowBits is 0 in inflateInit2()
msg102016 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-03-31 15:40
The else branch of the test should also check that 0 does *not* raise an error.
msg102017 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-03-31 15:48
Ok, actually Python is only echoing the error return from zlib here, so I don't seen the point of the conditional. Just always test against -1 and we're done.
msg102020 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-31 16:52
@pitrou: because the op have the problem with 1.2.4 version of zlib. By the way i had just always test against -1 in my first patch. Make i a new patch with a simple correction with -1 in place of 0?

@david: i know, but i'm learning now the TDD, so excuse me if i make mistakes. How i check that a function don't raise an error? About the string comparison you right, this is the first thing that i thought, but when i looked the type of release number, in that moment i thought that the string comparison was ok.
msg102044 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-03-31 23:21
While i wait for what i have to do, i corrected the patch. But there is a problem: the version of zlib '1.2.3.3' raise an error on "distutils.version" module. The problem is caused by the regex expression in the "distutils.version" module:

version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
                            re.VERBOSE)

this expression don't match with the type of version that zlib.ZLIB_VERSION return.
msg102072 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-04-01 07:58
The "I'm not sure" in my comment really was a question, rather than a definite direction to conditionally retain the old test.

I've actually looked at the relevant C code in the zlib module now, and I agree with Antoine that the original suggestion of changing the 0 in the test to a -1 is fine (the test is just checking the handling of a Z_STREAM_ERROR return from the API call rather than anything more sophisticated).

Adding to my to-do list.
msg102073 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-04-01 08:08
Ok, so here the patch.
msg102478 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-04-06 17:27
Committed in r79848 (trunk), r79849 (py3k), r79850 (2.6), r79851 (3.1). Thank you!
msg102485 - (view) Author: Valerio Turturici (valerio.turturici) Date: 2010-04-06 19:02
Thanks to you! This was my first patch, i'm very happy to contribute :)
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52440
2010-04-06 19:02:38valerio.turturicisetmessages: + msg102485
2010-04-06 17:27:30pitrousetstatus: open -> closed
resolution: fixed
messages: + msg102478

stage: patch review -> resolved
2010-04-06 17:12:29piotosetnosy: + pioto
2010-04-01 08:08:58valerio.turturicisetfiles: + 8193.patch

messages: + msg102073
2010-04-01 08:08:25valerio.turturicisetfiles: - 8193.patch
2010-04-01 07:58:26ncoghlansetassignee: ncoghlan
messages: + msg102072
2010-03-31 23:21:43valerio.turturicisetfiles: + 8193.patch

messages: + msg102044
2010-03-31 23:03:57valerio.turturicisetfiles: - 8193.patch
2010-03-31 16:52:05valerio.turturicisetmessages: + msg102020
2010-03-31 15:49:00pitrousetmessages: + msg102017
2010-03-31 15:40:02r.david.murraysetmessages: + msg102016
2010-03-31 15:21:52amaury.forgeotdarcsetmessages: + msg102015
2010-03-31 15:16:39r.david.murraysetmessages: + msg102014
2010-03-31 14:38:25pitrousetnosy: + pitrou
messages: + msg102012
2010-03-31 13:58:51michael.foordsetnosy: + michael.foord
messages: + msg102010
2010-03-31 13:57:22valerio.turturicisetfiles: + 8193.patch

messages: + msg102009
2010-03-31 13:24:20valerio.turturicisetfiles: - 8193.patch
2010-03-31 13:18:33valerio.turturicisetmessages: + msg102003
2010-03-31 12:09:34r.david.murraysetmessages: + msg102000
2010-03-30 11:33:16valerio.turturicisetmessages: + msg101934
2010-03-30 11:32:10valerio.turturicisetmessages: + msg101933
2010-03-30 09:32:56valerio.turturicisetmessages: + msg101925
2010-03-30 09:24:04valerio.turturicisetmessages: + msg101924
2010-03-30 09:10:30ncoghlansetnosy: + ncoghlan
messages: + msg101923
2010-03-30 09:01:39valerio.turturicisetmessages: + msg101922
2010-03-30 01:08:43r.david.murraysetpriority: normal
versions: + Python 2.6, Python 3.1, Python 2.7, Python 3.2, - Python 2.5
nosy: + r.david.murray

messages: + msg101911

stage: patch review
2010-03-30 00:02:56valerio.turturicisetfiles: + 8193.patch

messages: + msg101910
2010-03-29 23:09:04valerio.turturicisetmessages: + msg101909
2010-03-29 22:28:13valerio.turturicisetnosy: + valerio.turturici
messages: + msg101908
2010-03-26 14:54:28amaury.forgeotdarcsetkeywords: + patch, easy
nosy: + amaury.forgeotdarc
messages: + msg101751

2010-03-21 19:14:58Arfreversetnosy: + Arfrever
2010-03-21 19:12:48arekmcreate