Opened 6 months ago

Last modified 4 months ago

#16192 portneeded defect (port to stable)

PNG images crash wxCocoa on OS 10.5 & 10.6 if wxCocoa built on OS 10.7 or later

Reported by: charliefenton Owned by: SC
Priority: normal Milestone: 3.0.2
Component: wxOSX-Cocoa Version: 3.0.0
Keywords: PNG crash zlib Cc:
Blocked By: Blocking:
Patch: no


If you build wxCocoa on OS 10.8 or OS 10.9 and then run the built application on OS 10.5 or OS 10.6, it will crash when loading or processing a PNG image, even if wxCocoa was built with the OS X Deployment target set to OS X 10.5 or 10.6 (-DMAC_OS_X_VERSION_MAX_ALLOWED=1050).

The problem stems from the fact that line 31 of wxWidgets-3.0.0/src/png/pngstruct.h has:

#include "zlib.h"

and gets the value of ZLIB_VERNUM from that header file. But zlib is not in the OSX SDK, so zlib.h is brought in from the version of zlib provided with OS 10.7, 10.8 or OS 10.9, which have zlib 1.2.5:

#define ZLIB_VERNUM 0x1250

while OS 10.5 and OS 10.6 have zlib 1.2.3:

#define ZLIB_VERNUM 0x1230

The crash occurs in wxWidgets-3.0.0/src/png/pngrutil.c lines 381 - 307, which call inflateReset2() or inflateInit2() if ZLIB_VERNUM is at least 1240 (zlib 1.2.4). Since zlib 1.2.3 does not have these functions, the application crashes.

My suggested fix is to add the source files and headers in wxWidgets-3.0.0/src/zlib to the wxCocoa.xcodeproj, and to add wxWidgets-3.0.0/src/zlib to the project's header search path, so that the pnglib will be linked with them instead of the zlib provided by OS X. (The zlib sources in wxWidgets are version 1.2.8 and so are newer than those provided with OS 10.9.)

This bug probably applies to wxCarbon as well as wxCocoa, but I haven't tested that.

Change History (11)

comment:1 Changed 5 months ago by vadz

Does this affect the command line build as well? I think that if you use configure+make, the included zlib headers should be already used, could you please test this?

comment:2 Changed 5 months ago by csomor

the configure flags I recommend for reasons of binary incompatibility

../configure --with-zlib=builtin --without-libiconv --without-liblzma  

comment:3 Changed 5 months ago by csomor

I'll add the zlib part to the xcodeproj builder script

comment:4 Changed 5 months ago by SC

In 76382:

adapting xcode build templates and config file to built-in zlib sources, see #16192

comment:5 Changed 5 months ago by SC

In 76383:

adding built-in zlib sources, see #16192

comment:6 Changed 5 months ago by SC

In 76384:

recreated project files, see #16192

comment:7 Changed 5 months ago by SC

  • Owner set to SC
  • Resolution set to fixed
  • Status changed from new to closed

In 76385:

removes zlib link statement from static builds, closes #16192

comment:8 Changed 4 months ago by charliefenton

  • Resolution fixed deleted
  • Status changed from closed to reopened

Change sets 75382, 76384 and 76385 are missing from the wxWidgets-WX_3_0_BRANCH, I downloaded the branch from GIT in response to Vadim's request for help with testing 3.0.1, using the link provided in that blog, and these changes are missing from wxWidgets-WX_3_0_BRANCH/build/osx/wxcocoa.xcodeproj/project.pbxproj. I did not check the other change sets associated with this bug report.

comment:9 Changed 4 months ago by neis

  • Resolution set to port to stable
  • Status changed from reopened to portneeded

comment:10 Changed 4 months ago by vadz

If anybody could please update the Xcode projects it would be really welcome. I'm not on friendly terms with Xcode myself...

comment:11 Changed 4 months ago by vadz

  • Milestone changed from 3.0.1 to 3.0.2

Would be nice to do this for 3.0.2. In the meanwhile I recommend using configure && make to build the library.

Note: See TracTickets for help on using tickets.