Page 1 of 1

Segmentation fault on ImageToBlob if compression failed

Posted: 2009-03-19T09:07:19-07:00
by ragesteel
Segmentation fault on ImageToBlob if compression failed.

Yes, it is also a bug in JasPer, that cannot compress such image, but it is not reason to Segmentation fault.
If i use WriteImage instead of ImageToBlob, i got just get false as result.

Image for test: http://img.gt2.ru/idx-83.bmp
ImageMagick version: 6.5.0-2
Operation system: openSUSE 11.1

Some problem also appeared on CentOS 5.2 with ImageMagick 6.4.9-4

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <magick/MagickCore.h>

int main(int argc, char **argv) {
	char *path = argv[0];

	ExceptionInfo *exception_info;
	ImageInfo *image_info, *jp2_image_info;
	Image *image;
	unsigned char *image_blob;
	size_t image_blob_len;
	MagickBooleanType write_image_rc;

	MagickCoreGenesis(path, MagickTrue);

	image_info = CloneImageInfo((ImageInfo *) NULL);
	(void) strcpy(image_info->filename, "idx-83.bmp");

	exception_info = AcquireExceptionInfo();
        image = ReadImage(image_info, exception_info);

	if (UndefinedException != exception_info->severity) {
		CatchException(exception_info);
	}
	if ((Image *) NULL == image) {
		fprintf(stderr, "Unable to read image file!\n");
		exit(1);
	}

	// WriteImage at least does not crush whole application
	jp2_image_info = CloneImageInfo((ImageInfo *) NULL);
	(void) strcpy(jp2_image_info->filename, "idx-83.jp2");
	write_image_rc = WriteImage(jp2_image_info, image);
	fprintf(stdout, "Write image result: %d\n", write_image_rc);
	jp2_image_info = DestroyImageInfo(jp2_image_info);

	// ImageToBlob does crush
        jp2_image_info = CloneImageInfo((ImageInfo *) NULL);
	(void) strcpy(jp2_image_info->magick, "JP2");

	image_blob = ImageToBlob(jp2_image_info, image, &image_blob_len, exception_info);
	fprintf(stdout, "Image blob length is %d\n", image_blob_len);


	jp2_image_info = DestroyImageInfo(jp2_image_info);
      	image = DestroyImage(image);
	image_info = DestroyImageInfo(image_info);
    	exception_info = DestroyExceptionInfo(exception_info);

	MagickCoreTerminus();
	return 0;
}

Re: Segmentation fault on ImageToBlob if compression failed

Posted: 2009-03-19T09:37:12-07:00
by magick
We have a fix for the problem you reported. Look for it in the Subversion trunk by sometime tomorrow.