Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
UIImagePNGRepresentation Crash
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3602632c __pthread_kill + 8
1 libsystem_c.dylib 0x323de29f abort + 94
2 ImageIO 0x37eca8bf png_error + 114
3 ImageIO 0x37ec9fe3 png_write_end + 46
4 ImageIO 0x37ec6069 writeOnePng + 2260
5 ImageIO 0x37ec578b _CGImagePluginWritePNG + 82
6 ImageIO 0x37ec56fd CGImageDestinationFinalize + 132
7 UIKit 0x37342fa7 UIImagePNGRepresentation + 274
Note: Image data is not nil.
Copy link

pburleson commented May 24, 2012

The exception code:

Exception Type: SIGABRT
Exception Codes: #0 at 0x3602632c
Crashed Thread: 0

Copy link

JensAyton commented May 24, 2012

It looks like the CG PNG plug-in is either failing to call png_set_error_fn(), or using an error handler which returns (instead of longjmping away or throwing an exception). It is then issuing an invalid sequence of PNG writing calls. Libpng is built with setjmp support disabled, so the default error handler aborts.

Presumably not every call to UIImagePNGRepresentation() triggers this crash, so there’s probably something about your usage that’s triggering the invalid sequence (for instance, a zero-sized image might lead to no IDAT chunks being written, which seems to be the only call to png_error() in png_write_end() itself).

Tl;dr: the specific crash is an Apple bug, but even if they fixed it it must be triggered by some problem on your end.

Copy link

dlinsin commented May 25, 2012

We had problems with UIImagePNGRepresentation related to corrupted images, downloaded from a web server. You could identify the corrupted images, by trying to look at them in Safari.

Copy link

RestlessThinker commented Aug 16, 2012

Did you ever find the root of this problem or a solution for this? I'm having the same crash. The images could be downloaded from a web server. I'm thinking of checking the first 8 bytes to confirm it's a PNG but I'm not sure if a zero-sized image would contain this or not.

Copy link

reidmain commented Aug 31, 2012

I'm having this same problem. Attempts to create "bad" UIImages and serialize them using UIImagePNGRepresentation have proved fruitless. My current attempt to figure out what is causing this call to png_error() is create a text file with all the URLs of every possible image in our app and then create a simple iOS app that downloads every image and then attempts to serialize it. I hope this will point out which images are corrupt then allow us to fix it as well as put in some preventative code that will prevent this crash from happening in the case that someone uploads a corrupted image again.

I'll post back with my progress.

Copy link

reidmain commented Aug 31, 2012

Unfortunately after downloading 7500+ images I experienced no errors.

One interesting note is that the crash reports are only for iOS 5.1+.

Copy link

leftspin commented Feb 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment