Page 1 of 1

Perl API: Segmentation fault on Animated GIF thumbnail op

Posted: 2009-06-29T12:10:51-07:00
by imagemagick
When trying to thumbnail an animated GIF file, the script (attached) seg faulted. I have attached the version information, backtrace, snippet of code and the animated GIF.

Few Data Points:
1. I tried to step through the code to find the operation which causes the memory corruption and believe that it is in the SyncAuthenticPixels op (called from SampleImage). I might be wrong here but have added this information in case it helps in debugging this issue further.

2. The crash does not happen will all animated GIF's

3. Crash does not happen when the dimensions are modified to a different values say 40x40 as opposed to to 10x15 (as in the script)

4. I tried the convert routine for a similar operation and it worked fine -
convert ./animation.gif -thumbnail 15x10 ./an-im.jpg

ImageMagick:
Version 6.5.1-10
OS - FreeBSD-6.4.10 amd64

Backtrace:
Program received signal SIGBUS, Bus error.
0x0000000800e401e7 in GetImageListLength (images=0xd0d038381d1d) at magick/list.c:613
613 images=images->previous;
(gdb) bt
#0 0x0000000800e401e7 in GetImageListLength (images=0xd0d038381d1d) at magick/list.c:613
#1 0x0000000800e8858b in ThumbnailImage (image=0x724000, columns=140737488325536, rows=8204288, exception=0x6c9280) at magick/resize.c:2933
#2 0x0000000800c69279 in XS_Image__Magick_Mogrify (cv=0xd0d038381d1d) at Magick.xs:8694
#3 0x000000000046125a in Perl_pp_entersub ()
#4 0x000000000045a88e in Perl_runops_standard ()
#5 0x0000000000418000 in perl_run ()
#6 0x0000000000417ccc in perl_run ()
#7 0x0000000000415484 in main ()

Snippet of code which causes the crash:

Code: Select all

use Image::Magick;
use strict;
use warnings;

sub thumbnail_imagemagick
{
	my $content = shift;
	my $data_ref = shift;

	my $width = 15;
	my $height = 10;
	my $image = Image::Magick->new();
	$image->BlobToImage($content);
	$image->Thumbnail("${width}x${height}");
	$image->Set(magick => 'JPG');
	$image->Set(quality => 70); 
	$$data_ref = $image->ImageToBlob();
	return 0;
}

my $dataOut;
my $content;
my $imageFile = "./animation.gif";

open FP,"$imageFile" or die "Unable to open $imageFile";
binmode(FP);
my $n=0;
my $data;
while (($n = read FP, $data, 4) != 0) {
	$content .= $data; 
}

close(FP);
thumbnail_imagemagick($content,\$dataOut);
Animated GIF
Download the animation from this link -
http://www.bigoo.ws/code/preview/229489.htm

Re: Perl API: Segmentation fault on Animated GIF thumbnail op

Posted: 2009-06-29T12:32:36-07:00
by magick
We ran your script over 10,000 iterations without any faults. We're using ImageMagick 6.5.4-0.

Re: Perl API: Segmentation fault on Animated GIF thumbnail op

Posted: 2009-06-29T13:48:58-07:00
by imagemagick
I download the source code for version 6.5.4-0, compiled and installed the same. The bus error:10 still happens for the same test-case. I am not sure of the difference between our respective setup. I am using

1. FreeBSD.6.4.10
2. g++ (GCC) 3.4.6 [FreeBSD]
3. perl, v5.6.1
3. An excerpt from the config.log file is attached below.

Any help in deciphering this would be appreciated. Please let me know if specific information regarding the setup is required and I can provide them.

Code: Select all


                  Option                        Value
-------------------------------------------------------------------------------
Shared libraries  --enable-shared=yes           yes
Static libraries  --enable-static=yes           yes
Module support    --with-modules=yes            yes
GNU ld            --with-gnu-ld=yes             yes
Quantum depth     --with-quantum-depth=16       16
High Dynamic Range Imagery
                  --enable-hdri=no              no

Delegate Configuration:
BZLIB             --with-bzlib=yes              yes
Autotrace         --with-autotrace=no           no
DJVU              --with-djvu=yes               no
DPS               --with-dps=yes                no
FlashPIX          --with-fpx=yes                no
FontConfig        --with-fontconfig=no          no
FreeType          --with-freetype=yes           no
GhostPCL          None                          pcl6 (unknown)
GhostXPS          None                          gxps (unknown)
Ghostscript       None                          gs (unknown)
Ghostscript fonts --with-gs-font-dir=default    none
Ghostscript lib   --with-gslib=no               no
Graphviz          --with-gvc=yes                no
JBIG              --with-jbig=yes               no
JPEG v1           --with-jpeg=yes               yes
JPEG-2000         --with-jp2=yes                no
LCMS              --with-lcms=yes               no
LQR               --with-lqr=yes                no
Magick++          --with-magick-plus-plus=yes   yes
OpenEXR           --with-openexr=yes            no
PERL              --with-perl=yes               /usr/local/bin/perl
PNG               --with-png=yes                no
RSVG              --with-rsvg=no                no
TIFF              --with-tiff=yes               no
Windows fonts     --with-windows-font-dir=      none
WMF               --with-wmf=yes                no
X11               --with-x=                     no
XML               --with-xml=no         no
ZLIB              --with-zlib=yes               yes

X11 Configuration:
      X_CFLAGS        =
      X_PRE_LIBS      =
      X_LIBS          =
      X_EXTRA_LIBS    =

Options used to compile and link:
  PREFIX          = /usr/local
  EXEC-PREFIX     = /usr/local
  VERSION         = 6.5.4
  CC              = gcc -std=gnu99
  CFLAGS          = -g -O2 -Wall -W -D_THREAD_SAFE -pthread
  MAGICK_CFLAGS   = -g -O2 -Wall -W -D_THREAD_SAFE -pthread
  CPPFLAGS        = -I/usr/local/include/ImageMagick
  PCFLAGS         =
  DEFS            = -DHAVE_CONFIG_H
  LDFLAGS         = -L/usr/local/lib64
  MAGICK_LDFLAGS  = -L/usr/local/lib -L/usr/local/lib64
  LIBS            = -lMagickCore -ljpeg -lbz2 -lz -lm -lc_r
  CXX             = g++
  CXXFLAGS        = -g -O2 -Wall -W -D_THREAD_SAFE -pthread

Re: Perl API: Segmentation fault on Animated GIF thumbnail op

Posted: 2009-06-29T17:40:37-07:00
by magick
We tried your script on a different host and can reproduce the problem. We will have a patch to fix the problem without the next day or two. Thanks.

Re: Perl API: Segmentation fault on Animated GIF thumbnail op

Posted: 2009-12-18T23:04:33-07:00
by meeko
Has this problem been fixed yet? I'm now encountering the exact same problem with a perl app I am creating that uses Image::Magick to create thumbnails of images that people upload, by using the Thumbnail() method. Whenever the image is an animated gif, the app segfaults. However, the Resize() method works fine even on animated gifs, although it results in a larger filesize, so I would really like to use Thumbnail() instead.

Is there a fix for this problem, and if not then I have a second question. Is there a way with Image::Magick to determine if an image is an animated gif? If there is, I can first perform that check and if it is, then use Resize() to create the thumbnail, and use Thumbnail() on all other images. If not, my last, and least desireable option would be to just use Resize() on all gifs, and Thumbnail() on other images, but I would really like to use Thumbnail() whenever possible as it results in a much smaller filesize. Thanks for any help!

Re: Perl API: Segmentation fault on Animated GIF thumbnail op

Posted: 2009-12-19T09:09:26-07:00
by fmw42
in command line see %n for number of scenes at http://www.imagemagick.org/script/escape.php

convert image.gif -ping -format "%n" info:

Don't know how that converts to PerlMagick, but see this posting viewtopic.php?f=1&t=15204

Re: Perl API: Segmentation fault on Animated GIF thumbnail op

Posted: 2009-12-19T23:32:35-07:00
by meeko
Thanks for the information. I read the post you suggested and I was able to solve my problem. Here's all I did, in case anyone else encounters this and just needs an easy fix.

On the line where I read the image in, I just changed the line:

$image->Read("$filename");

to

$image->Read("{$filename}[0]");

This forces only first frame of the image to be read, which solves the problem for all image files, whether its an animated gif or not. Now the thumbnail creation portion of my app is working fine.

Re: Perl API: Segmentation fault on Animated GIF thumbnail o

Posted: 2010-02-15T01:42:33-07:00
by dcweeks
Thanks so much Meeko.... worked like a charm and kept me truckin along in writing my code.

Re: Perl API: Segmentation fault on Animated GIF thumbnail o

Posted: 2011-08-26T02:50:49-07:00
by marsh
The same thing still happens with 6.7.1-10.

Solution is posted at cpan.
https://rt.cpan.org/Public/Bug/Display.html?id=70471

Re: Perl API: Segmentation fault on Animated GIF thumbnail o

Posted: 2011-08-26T05:06:53-07:00
by magick
We have a patch to fix the fault in ImageMagick 6.7.2-0 which is scheduled for release within a few days.