PNG expected N bytes; found N bytes.

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
mrmaxm
Posts: 1
Joined: 2017-03-28T08:25:08-07:00
Authentication code: 1151

PNG expected N bytes; found N bytes.

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG expected N bytes; found N bytes.

Post 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.
Post Reply