lvandeve / lodepng

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

Writing 32k PNG results in invalid PNG #46

Open CryptoCrocodile opened 7 years ago

CryptoCrocodile commented 7 years ago

I can't seem to be able to write 32k PNGs. Affinity Photo and Photoshop both seem to be able to write PNGs with up to 32767x32767 in both 8bit and 16bit modes so it seems to be supported by the spec. 16k PNGs seem to work.

EDIT: it's worth mentioning that writing a 30000x30000 greyscale+alpha texture seems to work.

CryptoCrocodile commented 7 years ago

FWIW, it doesn't seem to be related to the deflate/libz code, I've swapped it out with libz and it still produces invalid PNGs. Also it seems to be related to a narrowing cast to int, as an RGB 8bpp image of 27000x27000 produces an invalid image (2.187.000.000 bytes) but a 26700x26700 image is still valid (2.138.670.000 bytes) so the 27000^2 image seems to overflow a signed integer somewhere.