]> git.imager.perl.org - imager.git/commitdiff
backport fix for RT issue 18397
authorTony Cook <tony@develop=help.com>
Thu, 30 Mar 2006 07:14:17 +0000 (07:14 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 30 Mar 2006 07:14:17 +0000 (07:14 +0000)
jpeg.c
t/t101jpeg.t
t/t108tga.t
tga.c

diff --git a/jpeg.c b/jpeg.c
index 141ac4ccdce793926b59f255642a40bb9dcf5314..dc6b0b182b45c9c910caccbe9f210dd6239e55ad 100644 (file)
--- 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 */
index a707068fbc3343c805526bbf1e0dea9a9b247381..049643bac882050956dae6ff7e6d42aab1e78949 100644 (file)
@@ -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");
+  }
 }
 
index 6e239f7aa83d68cc24d42b59c4284add178a8638..f6d6857bb3912bf69ae7f9b76c9b68415b241f5b 100644 (file)
@@ -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 b26081091b26811f41e6631d410f7d40a161bd8e..7426339e8c3ebb57352002c341530ea67dc6ab1d 100644 (file)
--- 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;