Page 1 of 1

PNG expected N bytes; found N bytes.

Posted: 2017-03-28T08:34:19-07:00
by mrmaxm
I've got an image, that seems to be corrupted but only to certain extend. Viewers actually are able to preview it (browser, and ubuntu image viewers).

So this works:

Code: Select all

identify image.png
Outputs:

Code: Select all

image.png PNG 1024x1024 1024x1024+0+0 8-bit sRGB 492KB 0.000u 0:00.000
But this command:

Code: Select all

identify -verbose image.png
Or:

Code: Select all

identify -format "%A" image.png
Fails with error:

Code: Select all

identify: Expected 8192 bytes; found 8067 bytes `image.png' @ warning/png.c/MagickPNGWarningHandler/1683.
identify: Read Exception `image.png' @ error/png.c/MagickPNGErrorHandler/1650.
identify: corrupt image `image.png' @ error/png.c/ReadPNGImage/4029.
And URL to image: https://s3-eu-west-1.amazonaws.com/stat ... /image.png

So behaviour here is a bit inconsistent, and many other vendors choose to "deal" with such files by partially rendering it.
To help developers to use tool, it would be good to be able to identify corruption of file in all cases and print consistent info that file is corrupted so developers can make their app logic to react accordingly.

Re: PNG expected N bytes; found N bytes.

Posted: 2017-03-28T08:55:41-07:00
by glennrp
"Identify" only reads the header, and in this case there is nothing wrong with the header.
If you ask "identify" to provide more details (with "identify -verbose" or "identify -format...")
then it reads the entire file and discovers that it's truncated.

You can force "identify" to check the entire file with "identify +ping image.png" but
it is of course slower that way.