Page 1 of 1

Segmentation fault writing an image

Posted: 2008-01-10T06:56:16-07:00
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)

Re: Segmentation fault writing an image

Posted: 2008-01-11T09:12:20-07:00
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;
}


Re: Segmentation fault writing an image

Posted: 2008-01-11T10:03:37-07:00
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.

Re: Segmentation fault writing an image

Posted: 2008-01-12T18:26:13-07:00
by mkoppanen
Looks like a I had a little older version on my 32bit. Thank you for the fix!