[rt #68993] check the number of conv coefficients is positive
authorTony Cook <tony@develop-help.com>
Sat, 15 Oct 2011 01:48:26 +0000 (12:48 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 15 Oct 2011 01:48:26 +0000 (12:48 +1100)
Changes
conv.im
t/t61filters.t

diff --git a/Changes b/Changes
index fba644e..a57f364 100644 (file)
--- a/Changes
+++ b/Changes
@@ -53,6 +53,9 @@ Bug fixes:
  - updated the Thanks list in README
    https://rt.cpan.org/Ticket/Display.html?id=71607
 
+ - check there's at least one coefficient for the convolution filter
+   https://rt.cpan.org/Ticket/Display.html?id=68993
+
 Imager 0.85_01 - 10 Oct 2011
 ==============
 
diff --git a/conv.im b/conv.im
index b766d7e..f02db85 100644 (file)
--- a/conv.im
+++ b/conv.im
@@ -22,6 +22,11 @@ i_conv(i_img *im, const double *coeff,int len) {
 
   mm_log((1,"i_conv(im %p, coeff %p, len %d)\n",im,coeff,len));
   i_clear_error();
+
+  if (len < 1) {
+    i_push_error(0, "there must be at least one coefficient");
+    return 0;
+  }
  
   center=(len-1)/2;
 
index b9e0005..84bdc44 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use Imager qw(:handy);
-use Test::More tests => 113;
+use Test::More tests => 116;
 
 -d "testout" or mkdir "testout";
 
@@ -23,6 +23,15 @@ test($imbase, {type=>'contrast', intensity=>0.5},
 test($imbase, {type=>'conv', coef=>[ 0.3, 1, 0.3, ], },
      'testout/t61_conv_blur.ppm');
 
+{
+  my $work = $imbase->copy;
+  ok(!Imager::i_conv($work->{IMG}, []), "conv should fail with empty array");
+  ok(!$work->filter(type => 'conv', coef => []),
+     "check the conv OO intergave too");
+  is($work->errstr, "there must be at least one coefficient",
+     "check conv error message");
+}
+
 {
   my $work8 = $imbase->copy;
   ok(!$work8->filter(type => "conv", coef => "ABC"),