[rt #79922] catch an invalid matrix supplied to convert()
authorTony Cook <tony@develop-help.com>
Sat, 29 Sep 2012 01:22:08 +0000 (11:22 +1000)
committerTony Cook <tony@develop-help.com>
Sat, 29 Sep 2012 01:22:08 +0000 (11:22 +1000)
Imager.pm
Imager.xs
t/t67convert.t

index 71af06867ce35bf7a66764ce7029194b08e83db3..90d548e83ba0fad2843a2db4c63672b88224468d 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -3581,6 +3581,7 @@ sub convert {
   $new->{IMG} = i_convert($self->{IMG}, $matrix);
   unless ($new->{IMG}) {
     # most likely a bad matrix
+    i_push_error(0, "convert");
     $self->{ERRSTR} = _error_as_msg();
     return undef;
   }
index 2a01e2a88476ea27c3e122d397fd5a6ece841c02..f2e13576505630a68fd2c18a1f038591a27b3d28 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -2035,6 +2035,10 @@ i_convert(src, avmain)
              if (len > inchan)
                inchan = len;
            }
+           else {
+             i_push_errorf(0, "invalid matrix: element %d is not an array ref", j);
+             XSRETURN(0);
+           }
           }
           coeff = mymalloc(sizeof(double) * outchan * inchan);
          for (j = 0; j < outchan; ++j) {
index 94e2a961e623eb026406bcc6824eef0ec49a33d2..eccc59117e70602ac736991be4d4d2a42544bfab 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use Imager qw(:all :handy);
-use Test::More tests => 27;
+use Test::More tests => 29;
 use Imager::Test qw(test_colorf_gpix is_fcolor1 is_fcolor3);
 
 -d "testout" or mkdir "testout";
@@ -140,3 +140,12 @@ SKIP:
   my $conv = $im->convert(preset => 'grey');
   is($conv->bits, 'double', 'make sure result has extra bits');
 }
+
+{ # http://rt.cpan.org/NoAuth/Bug.html?id=79922
+  # Segfault in convert with bad params
+  my $im = Imager->new(xsize => 10, ysize => 10);
+  ok(!$im->convert(matrix => [ 10, 10, 10 ]),
+     "this would crash");
+  is($im->errstr, "convert: invalid matrix: element 0 is not an array ref",
+     "check the error message");
+}