Title: zlibmodule cannot handle Z_VERSION_ERROR zlib error
Type: crash Stage: resolved
Components: Extension Modules Versions: Python 3.2, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nadeem.vawda Nosy List: nadeem.vawda, python-dev, rmtew
Priority: normal Keywords: patch

Created on 2011-08-25 05:21 by rmtew, last changed 2011-09-04 06:56 by python-dev. This issue is now closed.

File name Uploaded Description Edit
zlibmodule.patch rmtew, 2011-08-25 07:00
Messages (6)
msg142954 - (view) Author: (rmtew) Date: 2011-08-25 05:21
zlibmodule.c calling inflateInit2 and deflateInit2 will subsequently proceed to crash in the case where these functions return Z_VERSION_ERROR.

zlib implementation note:

When you compile against zlib, several functions (actually macros) like inflateInit2 and deflateInit2 compile the version of zlib you are compiling against into the actual call of the underlying real zlib API function.

Our situation:

We are compiling Python as a static library.  When we link Python against our main project,  it links against the version of zlib used by that main project.  The version numbers are different, and rather than getting a nice exception we get a crash.

Expected result:

Proper error handling in zlibmodule.c, and not crash.  Unhandled errors in zlibmodule.c are passed into the custom function zlib_error which looks at the msg field of the zst struct.  In the case of Z_VERSION_ERROR the msg field is not initialised and a crash will result from use of the nonsense value in msg.
msg142958 - (view) Author: (rmtew) Date: 2011-08-25 07:00
Attached is a patch to fix the issue, generated using "p4 diff -du" which should hopefully be usable.
msg142962 - (view) Author: Nadeem Vawda (nadeem.vawda) * (Python committer) Date: 2011-08-25 08:19
Thanks for the bug report and patch. I'll take a look at it over the weekend.
msg143093 - (view) Author: Roundup Robot (python-dev) Date: 2011-08-28 09:30
New changeset ba5000307b5d by Nadeem Vawda in branch '2.7':
Issue #12839: Fix crash in zlib module due to version mismatch.

New changeset cc9e794bf94f by Nadeem Vawda in branch '3.2':
Issue #12839: Fix crash in zlib module due to version mismatch.

New changeset b384231df332 by Nadeem Vawda in branch 'default':
Merge: #12839: Fix crash in zlib module due to version mismatch.
msg143125 - (view) Author: Nadeem Vawda (nadeem.vawda) * (Python committer) Date: 2011-08-28 21:09
Done. Once again, thanks for the report and the patch!
msg143486 - (view) Author: Roundup Robot (python-dev) Date: 2011-09-04 06:56
New changeset 2fb00b6ed17c by Nadeem Vawda in branch '3.2':
Issue #12839: Fix crash in zlib module due to version mismatch.
Date User Action Args
2011-09-04 06:56:36python-devsetmessages: + msg143486
2011-08-28 21:09:56nadeem.vawdasetstatus: open -> closed
resolution: fixed
messages: + msg143125

stage: resolved
2011-08-28 09:30:03python-devsetnosy: + python-dev
messages: + msg143093
2011-08-25 08:19:15nadeem.vawdasetnosy: + nadeem.vawda
messages: + msg142962

assignee: nadeem.vawda
components: + Extension Modules, - None
2011-08-25 07:00:49rmtewsetfiles: + zlibmodule.patch
keywords: + patch
messages: + msg142958
2011-08-25 05:21:49rmtewcreate