Subject: | writing a 2 or 4 channel jpeg to a scalar causes a segmentation fault |
The following produces a segmentation fault:
perl -MImager -e 'my $im = Imager->new(xsize => 100, ysize=>100,
channels => 4); $im->write(data=>\$foo, type=>"jpeg")'
This occurs because when the channel count is checked the iolayer passed
in hasn't been completely constructed, causing a NULL pointer deref when
it's destroyed.
There will be a 0.50 fix release within the next few days.
Workaround: check the channel count for an image is 1 or 3 channels
before attempting to save it as a jpeg.
The following path fixes the problem.
The next full release of Imager will move the code from
io_commit_types() into the base constructor, preventing this problem in
general.
--- jpeg.c.orig 2006-03-28 10:54:41.000000000 +1000
+++ jpeg.c 2006-03-28 10:55:33.000000000 +1000
@@ -413,6 +413,7 @@
mm_log((1,"i_writejpeg(im %p, ig %p, qfactor %d)\n", im, ig, qfactor));
i_clear_error();
+ io_glue_commit_types(ig);
if (!(im->channels==1 || im->channels==3)) {
i_push_error(0, "only 1 or 3 channels images can be saved as JPEG");
@@ -433,7 +434,6 @@
return 0;
}
- io_glue_commit_types(ig);
jpeg_wiol_dest(&cinfo, ig);
cinfo.image_width = im -> xsize; /* image width and height, in
pixels */