From 1e0418f1d05e29bd89ffcf454acbd9e14159ed70 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Sat, 15 Oct 2011 12:48:26 +1100 Subject: [PATCH] [rt #68993] check the number of conv coefficients is positive --- Changes | 3 +++ conv.im | 5 +++++ t/t61filters.t | 11 ++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index fba644ea..a57f364f 100644 --- 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 b766d7eb..f02db856 100644 --- 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; diff --git a/t/t61filters.t b/t/t61filters.t index b9e00054..84bdc447 100644 --- a/t/t61filters.t +++ b/t/t61filters.t @@ -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"), -- 2.39.5