s2png icon indicating copy to clipboard operation
s2png copied to clipboard

Does s2png protect against pngcrush and other optimizations?

Open elimisteve opened this issue 8 years ago • 3 comments

I'd like to store arbitrary data in imgur images, and supposedly they post-process the images using pngcrush.

If you happen to know ways to guard against this type of data corruption, please let me know! Thanks.

elimisteve avatar Nov 10 '16 23:11 elimisteve

pngcrush should not damage the data since the manipulations it performs are lossless as far as the actual pixels of the image go and s2png simply stores every three bytes of the input file as a pixel; it does not (ab)use PNG metadata. A quick practical test suggests that indeed pngcrush does not affect the data. A lossy PNG optimizer like pngquant will probably damage the data in an image it optimizes. You can use an archive file format with checksums (e.g., 7z) to make sure the damage doesn't go undetected.

As for Imgur, I tried uploading a 1.2 MiB PNG file generated with s2png and it recompressed it as JPEG, which, of course, is deadly to the data. A smaller ~280 KiB PNG survived intact. They didn't use pngcrush on it.

dbohdan avatar Nov 11 '16 16:11 dbohdan

@dbohdan Thanks for testing this! I will do some tests of my own, but so far it sounds like smaller files are safe but larger ones are not. I'll let you know what I find.

elimisteve avatar Nov 11 '16 23:11 elimisteve

You're welcome! I would guess the threshold for applying recompression is exactly 1 MiB.

dbohdan avatar Nov 12 '16 16:11 dbohdan

Close this issue due to inactivity. I think the question is answered.

dbohdan avatar Jan 03 '23 12:01 dbohdan