Opened 4 years ago

Closed 4 years ago

#16192 closed defect (fixed)

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

Reported by: charliefenton Owned by: disc
Priority: normal Milestone:
Component: wxOSX 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 (14)

comment:1 Changed 4 years 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 4 years ago by csomor

the configure flags I recommend for reasons of binary incompatibility

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

comment:3 Changed 4 years ago by csomor

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

comment:4 Changed 4 years ago by SC

In 76382:

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

comment:5 Changed 4 years ago by SC

In 76383:

adding built-in zlib sources, see #16192

comment:6 Changed 4 years ago by SC

In 76384:

recreated project files, see #16192

comment:7 Changed 4 years 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 years 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 years ago by neis

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

comment:10 Changed 4 years 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 years 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.

comment:12 Changed 4 years ago by vadz

  • Milestone 3.0.2 deleted

Unfortunately this can't be backported as is because r76384 contains changes to Scintilla files too and references sources only existing in the trunk version (e.g. LexDMAP.cxx), so it would break the build in 3.0 completely.

If somebody could manually update the Xcode project files to keep just the relevant changes, it would be great, but I am not going to be able to do it before 3.0.2 myself.

comment:13 Changed 4 years ago by disc

  • Owner changed from SC to disc
  • Status changed from portneeded to accepted

I'll take a peek today.

comment:14 Changed 4 years ago by DS

  • Resolution changed from port to stable to fixed
  • Status changed from accepted to closed

In 77954:

Fix crash with newer OS X builds running on older.

Use built-in zlib sources instead of system zlib. Backport of trunk
r76382, r76383, and r76385.

Closes #16192.

Note: See TracTickets for help on using tickets.