We are experiencing a strange crash where UIImagePNGRepresentation() is sometimes causing png_error calls. We have been unable to reproduce this error on any of our devices in house.
Here is an example of the stack trace from one of our HockeyApp crash logs:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3167132c __pthread_kill + 8
1 libsystem_c.dylib 0x33d6729f abort + 94
2 ImageIO 0x346c38bf png_error + 114
3 ImageIO 0x346c2fe3 png_write_end + 46
4 ImageIO 0x346bf069 writeOnePng + 2260
5 ImageIO 0x346be78b _CGImagePluginWritePNG + 82
6 ImageIO 0x346be6fd CGImageDestinationFinalize + 132
7 UIKit 0x31346e23 UIImagePNGRepresentation + 274
We have only been seeing this crash logs on devices running iOS 5.1+ and above. We've actually been getting crashes from iOS 6 as well so this bug has not yet been fixed.
I wrote a test app that downloads over 16,000 of the possible images that our app can display and all of them were able to be downloaded and saved to disk with no problems. Some responses to this gist imply that this issue could be caused by corrupted images but seeing as how I downloaded over 16,000 images and never once had an issue I don't think this could be the case.
The latest hypothesis I am working on is that somehow the data being downloaded is corrupted and therefore a corrupted UIImage is being created. However all attempts to create a corrupted UIImage have failed. Apple seems to have created a robust constructor for UIImage such that anything that I pass in which is invalid results in a nil being returned from the constructor.
Has anyone else experienced anything like this from UIImagePNGRepresentation?