PNG resize returns 0 bytes bug or corrupt image?

(fearlessfrog) #1

This PNG breaks on our version of Discourse 1.4.2, the small thumbnail png created version gives a

‘Resource interpreted as Document but transferred with MIME type image/png:’

…in Chrome error and returns 0 bytes. It seems not to be Chrome dependent, and IE 11, Win10 thing too.

We thought it might be our Cloudflare set-up, but it seems to be recreatable on too:

EDIT: Plus here too, which is good.

(fearlessfrog) #2

The original file name was called ‘Screen_151114_161146.png’ so when we try to rename it (perhaps a file name length bug in a PNG processing lib?) then ‘a.png’ will also fail. Thinking that Discourse might have a duplicate image check, we altered a pixel and saved the rename and it now seems to work. A clue, or just a side effect of resaving in Win10 Paint rather than the name?

EDIT: It appears to be the resaving that fixes it, pointing to the original format/outputter (a flight sim, obviously):

An imagemagick identify with verbose gives this error on the original non-working image:

identify -verbose Screen_151114_161146.png
identify.exe: Expected 8 bytes; found 0 bytes `Screen_151114_161146.png' @ warning/png.c/MagickPNGWarningHandler/1656.
identify.exe: Read Exception `Screen_151114_161146.png' @ error/png.c/MagickPNGErrorHandler/1630.
identify.exe: corrupt image `Screen_151114_161146.png' @ error/png.c/ReadPNGImage/3959.

…which is odd, as without a verbose check it looks ok:

identify Screen_151114_161146.png
Screen_151114_161146.png PNG 1920x1080 1920x1080+0+0 8-bit sRGB 2.118MB 0.000u 0:00.000

EDIT2: Further digging into the byzantine world of PNG encoding. Bad file:

.\pngcheck.exe .\Screen_151114_161146.png
.\Screen_151114_161146.png  file doesn't end with an IEND chunk

So, not sure that this is a Discourse issue at all. If RMagik is being being used, which eventually gets to libpng then the convert is not going to be able to open. The chances of that flight sim fixing a bug in their screenshot generation feature is pretty slim, which is unfortunate as we’re a flight sim forum. :frowning:

EDIT3: Yep, looks like it is failing silently here on the convert binary call:

convert.exe: Expected 8 bytes; found 0 bytes `.\Screen_151114_161146.png' @ warning/png.c/MagickPNGWarningHandler/1656.
convert.exe: Read Exception `.\Screen_151114_161146.png' @ error/png.c/MagickPNGErrorHandler/1630.
convert.exe: corrupt image `.\Screen_151114_161146.png' @ error/png.c/ReadPNGImage/3959.

(Jeff Atwood) #3

Nice research! Does seem like a corrupt image. Good for future reference if others run into this.

(fearlessfrog) #4

Thanks. It is interesting that the browser seems more liberal in being able to show the PNG original, so I guess it must be a different underlying library than the one used in convert.

One possible bug may be that the $? last command status from the convert isn’t been evaluated properly?

I’ll need to set up a dev env to try that out myself, but if the resize doesn’t complete successfully then shouldn’t the upload fail? If I can recreate it I’ll get together a PR.

PS Thanks to you and the team for Discourse - we love it.