Failed to convert PNG file with error " IDAT: invalid distance too far back"

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
long.to
Posts: 7
Joined: 2018-11-01T19:31:14-07:00
Authentication code: 1152

Failed to convert PNG file with error " IDAT: invalid distance too far back"

Post by long.to »

Hi,
When converting a PNG file to another file, I get an error:
convert.exe: IDAT: invalid distance too far back `C:\sample.png' @ error/png.c/MagickPNGErrorHandler/1714.
convert.exe: no images defined `C:\sample.png' @ error/convert.c/ConvertImageCommand/3300.
My sample argument is:

Code: Select all

convert.exe C:\sample.png C:\output.png
I'm using Windows 10 with lastest version of IM : ImageMagick-7.0.8-34

Here is my sample file: https://drive.google.com/file/d/1HHI43P ... 0TPWU/view
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Failed to convert PNG file with error " IDAT: invalid distance too far back"

Post by snibgo »

I get the same error message from IM.

Gimp can read the file with no complaint, but shows an image that is different to that shown on the web download page.

I suppose sample.png is corrupt.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Failed to convert PNG file with error " IDAT: invalid distance too far back"

Post by fmw42 »

On my Mac OSX with IM 6.9.10.34 Q16, I get an error message also

Code: Select all

convert sample.png test.png
convert: no images defined `test.png' @ error/convert.c/ConvertImageCommand/3258.

Mac PREVIEW opens it fine.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Failed to convert PNG file with error " IDAT: invalid distance too far back"

Post by dlemstra »

It appears that the zlib library is reporting this error. I looks like this is a corrupt image.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Failed to convert PNG file with error " IDAT: invalid distance too far back"

Post by 246246 »

pngfix (comes with libpng) will fix your png.

Code: Select all

$ pngcheck -v sample.png 
File: sample.png (2739 bytes)
  chunk IHDR at offset 0x0000c, length 13
    409 x 242 image, 8-bit palette, non-interlaced
  chunk PLTE at offset 0x00025, length 768: 256 palette entries
  chunk IDAT at offset 0x00331, length 1902
    zlib: deflated, 512-byte window, default compression
    zlib: inflate error = -3 (data error)
ERRORS DETECTED in sample.png

$ pngfix --out=new.png sample.png 
IDAT TFB default 9 15 1902 99220 sample.png

$ pngcheck -v new.png
File: new.png (2739 bytes)
  chunk IHDR at offset 0x0000c, length 13
    409 x 242 image, 8-bit palette, non-interlaced
  chunk PLTE at offset 0x00025, length 768: 256 palette entries
  chunk IDAT at offset 0x00331, length 1902
    zlib: deflated, 32K window, default compression
  chunk IEND at offset 0x00aab, length 0
No errors detected in new.png (4 chunks, 97.2% compression).

$ convert -verbose new.png out.png
new.png PNG 409x242 409x242+0+0 8-bit sRGB 256c 2739B 0.010u 0:00.000
new.png=>out.png PNG 409x242 409x242+0+0 8-bit sRGB 16c 2442B 0.000u 0:00.000
Post Reply