lvandeve / lodepng

PNG encoder and decoder in C and C++.
zlib License
2.06k stars 421 forks source link

LodePNG crashes when loading a 24bit PNG from file #72

Closed vkoskiv closed 6 years ago

vkoskiv commented 6 years ago

In function lodepng_inspect() in lodepng.c on line 3941: *w = lodepng_read32bitInt(&in[16]);

Crashes when trying to load this PNG: https://www.icloud.com/iclouddrive/0FyWzALaAoBRYh7cW6thjLUog#tonninseteli.png

I get EXC_BAD_ACCESS

System specs OS: macOS 10.14 Mojave (Darwin 18.0.0) Compiler: Apple LLVM 10.0.0

I tried merging in the latest version from this repo (20180326), and the problem persists.

vkoskiv commented 6 years ago

@lvandeve It seems it's unable to parse the width here, but I'm not sure why.

vkoskiv commented 6 years ago

Here is the PNG header hexdump:

00000000  89 50 4e 47 0d 0a 1a 0a  00 00 00 0d 49 48 44 52  |.PNG........IHDR|
00000010  00 00 01 f3 00 00 02 3a  08 06 00 00 00 33 00 a1  |.......:.....3..|
00000020  aa 00 00 00 04 67 41 4d  41 00 00 b1 8f 0b fc 61  |.....gAMA......a|
00000030  05 00 00 00 20 63 48 52  4d 00 00 7a 26 00 00 80  |.... cHRM..z&...|
00000040  84 00 00 fa 00 00 00 80  e8 00 00 75 30 00 00 ea  |...........u0...|
00000050  60 00 00 3a 98 00 00 17  70 9c ba 51 3c 00 00 00  |`..:....p..Q<...|
00000060  09 70 48 59 73 00 00 0b  13 00 00 0b 13 01 00 9a  |.pHYs...........|
00000070  9c 18 00 00 03 c2 69 54  58 74 58 4d 4c 3a 63 6f  |......iTXtXML:co|
00000080  6d 2e 61 64 6f 62 65 2e  78 6d 70 00 00 00 00 00  |m.adobe.xmp.....|
00000090  3c 78 3a 78 6d 70 6d 65  74 61 20 78 6d 6c 6e 73  |<x:xmpmeta xmlns|
vkoskiv commented 6 years ago

It also crashes when decoding a PNG encoded by LodePNG. (My initial tests were with a PNG encoded with Pixelmator)

vkoskiv commented 6 years ago

And, of course this is my fault. I'm passing in an incorrect value for the w and h.

Facepalm.

lvandeve commented 6 years ago

Thank you very much for reporting anyway! This is always very useful, even if it can sometimes be a false positive :)