Permalink
Browse files

[rt #79922] catch an invalid matrix supplied to convert()

  • Loading branch information...
1 parent deddc24 commit 26eb06ddf99c3b841ced9a41b4fdb036ab34fabc @tonycoz committed Sep 29, 2012
Showing with 15 additions and 1 deletion.
  1. +1 −0 Imager.pm
  2. +4 −0 Imager.xs
  3. +10 −1 t/t67convert.t
View
@@ -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;
}
View
@@ -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) {
View
@@ -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");
+}

0 comments on commit 26eb06d

Please sign in to comment.