ImageMagick crashes on large images

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
roundsturdy
Posts: 5
Joined: 2017-02-21T07:08:11-07:00
Authentication code: 1151

ImageMagick crashes on large images

Post by roundsturdy »

ImageMagick is not able to handle larges images. As you can see in the following code, I am running identify on a JPG of size 624x28281. I've tried to use the -limit parameter to to lift any memory-related restrictions, but there was no change. This seems to be a regression; this was definitely working with 6.8. I'm currently using version 6.9.7-4. Any help would be appreciated. Thanks.

$ identify pic.jpg
identify-im6.q16: memory allocation failed `pic.jpg' @ error/jpeg.c/ReadJPEGImage/1239.

$ file pic.jpg
pic.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 624x28281, frames 1

$ identify -limit map 128MB -limit memory 128MB -limit area 128MP pic.jpg
identify-im6.q16: memory allocation failed `pic.jpg' @ error/jpeg.c/ReadJPEGImage/1239.

$ identify --version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: ImageMagick crashes on large images

Post by snibgo »

Please don't multi-post. The bugs forum is the correct place to report suspected bugs. I've removed your other post.

What does "identify -list resource" say? How much memory do you have available?
snibgo's IM pages: im.snibgo.com
roundsturdy
Posts: 5
Joined: 2017-02-21T07:08:11-07:00
Authentication code: 1151

Re: ImageMagick crashes on large images

Post by roundsturdy »

Sorry, I wasn't sure where to post. To answer your questions:

$ identify -list resource
Resource limits:
Width: 16KP
Height: 16KP
Area: 128MP
Memory: 256MiB
Map: 512MiB
Disk: 1GiB
File: 768
Thread: 4
Throttle: 0
Time: unlimited

$ free -h
total used free shared buff/cache available
Mem: 23G 4.3G 1.3G 1.3G 17G 17G
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: ImageMagick crashes on large images

Post by snibgo »

Code: Select all

Height: 16KP
You only have permission for images up to that height, but yours is 28281. I suggest you adjust your policy.xml.

Your memory and disk limits are also very low.
snibgo's IM pages: im.snibgo.com
roundsturdy
Posts: 5
Joined: 2017-02-21T07:08:11-07:00
Authentication code: 1151

Re: ImageMagick crashes on large images

Post by roundsturdy »

Thanks for your response. Are these values that I should be able to adjust on the command line? If so, there doesn't seem to be any effect:

$ identify -limit memory 4GB -limit map 4GB -limit disk 20GB -limit area 500MP -limit height 50KP -limit width 50KP pic.jpg
identify-im6.q16: memory allocation failed `pic.jpg' @ error/jpeg.c/ReadJPEGImage/1239.

Can you suggest an alternative set of values?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: ImageMagick crashes on large images

Post by magick »

It looks like its failing before it gets to the policy check otherwise ImageMagick would throw:

Code: Select all

-> identify -verbose image.jpg
identify: width or height exceeds limit `logo.jpg' @ error/cache.c/OpenPixelCache/3827.
We can convert a large JPEG image with the latest ImageMagick releases, 7.0.5-0 and 6.9.7-9. Perhaps the problem is image specific. Can you post a URL to your JPEG image so we can download it and attempt to reproduce the problem?

Which OS are you using?
roundsturdy
Posts: 5
Joined: 2017-02-21T07:08:11-07:00
Authentication code: 1151

Re: ImageMagick crashes on large images

Post by roundsturdy »

Sure, here is the image in question: http://6jpuwudl6o60u5j2nvzjnd1aq9q.s3-w ... om/pic.jpg

I am using Debian stretrch, kernel 4.8.0-2-amd64.
roundsturdy
Posts: 5
Joined: 2017-02-21T07:08:11-07:00
Authentication code: 1151

Re: ImageMagick crashes on large images

Post by roundsturdy »

Thanks to snibgo's comment, I was able to solve the problem. The solution is indeed to adjust the height and width limits in policy.xml. I think there are actually two underlying problems here:

1. The "-limit width" and "-limit height" command line arguments are ignored. Apparently, these limits can be set only in policy.xml. This might be intentional for security reasons, but is confusing nonetheless. If it is fact an intentional design decision to ignore the flags, I think IM should at least emit a warning that it's ignoring them when they are provided. For example, in the following, notice that the limit width flag is ignored:

$ identify -limit width 100KP -list resource
Resource limits:
Width: 16KP
....

2. As pointed out by magick, when encountering an image that exceeds the width and height limits, it crashes with a memory error rather than emit a helpful message. This is definitely a bug.

Thank you both for your help. Let me know if I can do anything else for you.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: ImageMagick crashes on large images

Post by snibgo »

resource.xml is a security feature. The command-line "-limit" cannot relax the limits. It can only make them tighter, for example:

Code: Select all

f:\web\im>%IM%identify -limit width 100 -list resource

Resource limits:
  Width: 100P
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: ImageMagick crashes on large images

Post by magick »

With IMv7, we get expected results:

Code: Select all

-> identify pic.jpg 
identify: width or height exceeds limit `pic.jpg' @ error/cache.c/OpenPixelCache/3465.
identify: memory allocation failed `pic.jpg' @ error/jpeg.c/ReadJPEGImage/1270.
However, with IMv6, we just get the second message which is misleading. We will add a patch to fix this problem within the next few days.
oliverknill
Posts: 1
Joined: 2017-06-05T10:52:46-07:00
Authentication code: 1151

Re: ImageMagick crashes on large images

Post by oliverknill »

I have the same problem after updating to Ubuntu 17,04
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114
Convert refuses to resize larger panoramas which were no problem before.
" width or height exceeds limit "
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: ImageMagick crashes on large images

Post by snibgo »

See the above replies, in particular about policy.xml.
snibgo's IM pages: im.snibgo.com
Post Reply