From: Tony Cook Date: Thu, 30 Mar 2006 07:14:17 +0000 (+0000) Subject: backport fix for RT issue 18397 X-Git-Tag: Imager-0.51_01~23 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/0389bf4999294e6ae004d9383e2a09573efe47fd backport fix for RT issue 18397 --- diff --git a/jpeg.c b/jpeg.c index 141ac4cc..dc6b0b18 100644 --- a/jpeg.c +++ b/jpeg.c @@ -475,6 +475,7 @@ i_writejpeg_wiol(i_img *im, io_glue *ig, int qfactor) { 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"); @@ -495,7 +496,6 @@ i_writejpeg_wiol(i_img *im, io_glue *ig, int qfactor) { return 0; } - io_glue_commit_types(ig); jpeg_wiol_dest(&cinfo, ig); cinfo.image_width = im -> xsize; /* image width and height, in pixels */ diff --git a/t/t101jpeg.t b/t/t101jpeg.t index a707068f..049643ba 100644 --- a/t/t101jpeg.t +++ b/t/t101jpeg.t @@ -2,7 +2,7 @@ use strict; use lib 't'; use Imager qw(:all); -use Test::More tests => 54; +use Test::More tests => 56; init_log("testout/t101jpeg.log",1); @@ -30,7 +30,7 @@ if (!i_has_format("jpeg")) { $im = Imager->new(xsize=>2, ysize=>2); ok(!$im->write(file=>"testout/nojpeg.jpg"), "should fail to write jpeg"); cmp_ok($im->errstr, '=~', qr/format not supported/, "check no jpeg message"); - skip("no jpeg support", 50); + skip("no jpeg support", 52); } } else { open(FH,">testout/t101.jpg") || die "cannot open testout/t101.jpg for writing\n"; @@ -260,5 +260,17 @@ if (!i_has_format("jpeg")) { my %iptc = $im->parseiptc; ok(!$saw_warn, "should be no warnings"); } + + { # Issue # 18397 + # attempting to write a 4 channel image to a bufchain would + # cause a seg fault. + # it should fail still + my $im = Imager->new(xsize => 10, ysize => 10, channels => 4); + my $data; + ok(!$im->write(data => \$data, type => 'jpeg'), + "should fail to write but shouldn't crash"); + is($im->errstr, "only 1 or 3 channels images can be saved as JPEG", + "check the error message"); + } } diff --git a/t/t108tga.t b/t/t108tga.t index 6e239f7a..f6d6857b 100644 --- a/t/t108tga.t +++ b/t/t108tga.t @@ -2,7 +2,7 @@ use Imager qw(:all); use strict; use lib 't'; -use Test::More tests=>36; +use Test::More tests=>38; BEGIN { require "t/testtools.pl"; } init_log("testout/t108tga.log",1); @@ -115,6 +115,17 @@ is($compressed, 1, "check compressed tag"); Imager->set_file_limits(reset=>1); } +{ # Issue # 18397 + # the issue is for 4 channel images to jpeg, but 2 channel images have + # a similar problem on tga + my $im = Imager->new(xsize=>100, ysize=>100, channels => 2); + my $data; + ok(!$im->write(data => \$data, type=>'tga'), + "check failure of writing a 2 channel image"); + is($im->errstr, "Cannot store 2 channel image in targa format", + "check the error message"); +} + sub write_test { my ($im, $filename, $wierdpack, $compress, $idstring) = @_; local *FH; diff --git a/tga.c b/tga.c index b2608109..7426339e 100644 --- a/tga.c +++ b/tga.c @@ -833,6 +833,7 @@ i_writetga_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idst mm_log((1, "channels %d\n", img->channels)); i_clear_error(); + io_glue_commit_types(ig); switch (img->channels) { case 1: @@ -857,8 +858,6 @@ i_writetga_wiol(i_img *img, io_glue *ig, int wierdpack, int compress, char *idst return 0; } - io_glue_commit_types(ig); - header.idlength = idlen; header.colourmaptype = mapped ? 1 : 0; header.datatypecode = mapped ? 1 : img->channels == 1 ? 3 : 2;