Segmentation fault writing an image

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
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Segmentation fault writing an image

Post by mkoppanen »

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <wand/magick-wand.h>

int main(int argc,char **argv)
{
  MagickWand *magick_wand;

  magick_wand = NewMagickWand();

  MagickReadImage( magick_wand, "/var/www/test.png" );
  MagickWriteImage( magick_wand, "/tmp/test2.jpg" );
 
  magick_wand = DestroyMagickWand( magick_wand );

  return 0;
}
Linux 2.6.22 amd64. I get a segmentation fault if the target image exists but user does not have permissions to write to it. Using the latest ImageMagick (compiled from sources).

Code: Select all

www-data@laptop:~$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
www-data@laptop:~$ ls -l /tmp/test2.jpg
-rwx------ 1 mikko mikko 97710 2008-01-10 13:39 /tmp/test2.jpg
www-data@laptop:~$ ./a.out
Segmentation fault (core dumped)
Mikko Koppanen
My blog: http://valokuva.org
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Segmentation fault writing an image

Post by mkoppanen »

I refined the code a little further. When I compile this on 32bit Linux and run it runs without a crash. On 64 bit Linux I get a segmentation fault. I don't currently have a debug build so the backtrace is not that helpfull.

This seems to be happening everytime the file can not be written (dir does not exist, file permissions and so on).

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <wand/magick-wand.h>

int main(int argc,char **argv)
{
  MagickWandGenesis();

  MagickWand *magick_wand = NewMagickWand();
  PixelWand *pixel_wand = NewPixelWand();

  PixelSetColor( pixel_wand, "white" );

  MagickNewImage( magick_wand, 100, 100, pixel_wand );
  MagickSetImageFormat( magick_wand, "png" );

  MagickWriteImage( magick_wand, "/does/not/exist/test.png" );

  magick_wand = DestroyMagickWand( magick_wand );
  pixel_wand = DestroyPixelWand( pixel_wand );

  MagickWandTerminus();
  return 0;
}

Mikko Koppanen
My blog: http://valokuva.org
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Segmentation fault writing an image

Post by magick »

We can reproduce the problem you reported and have a patch in ImageMagick 6.3.7-10 Beta. The patch will be available sometime tomorrow. Thanks for the bug report.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Segmentation fault writing an image

Post by mkoppanen »

Looks like a I had a little older version on my 32bit. Thank you for the fix!
Mikko Koppanen
My blog: http://valokuva.org
Post Reply