From: Tony Cook Date: Tue, 12 Jun 2007 14:14:08 +0000 (+0000) Subject: - cropping outside the image would return an Imager object with X-Git-Tag: Imager-0.60~38 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/9fc9d0ca671ad89f34627cd21622bb4101609a5a - cropping outside the image would return an Imager object with no low-level image object, instead of returning false. Fixed by: Philip Gwyn (Leolo) http://rt.cpan.org/Ticket/Display.html?id=27509 --- diff --git a/Changes b/Changes index 64b01ef9..767c01ae 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,11 @@ Bug fixes: - fixes a regression introduced by the fixes for RT 11972 http://rt.cpan.org/Ticket/Display.html?id=27546 + - cropping outside the image would return an Imager object with + no low-level image object, instead of returning false. + Fixed by: Philip Gwyn (Leolo) + http://rt.cpan.org/Ticket/Display.html?id=27509 + Imager 0.58 - 16 May 2007 =========== diff --git a/Imager.pm b/Imager.pm index a4e3e070..5a3412e9 100644 --- a/Imager.pm +++ b/Imager.pm @@ -754,7 +754,10 @@ sub crop { $self->_set_error("resulting image would have no content"); return; } - + if( $r < $l or $b < $t ) { + $self->_set_error("attempting to crop outside of the image"); + return; + } my $dst = $self->_sametype(xsize=>$r-$l, ysize=>$b-$t); i_copyto($dst->{IMG},$self->{IMG},$l,$t,$r,$b,0,0); diff --git a/t/t65crop.t b/t/t65crop.t index 3f2728d1..5b98a135 100644 --- a/t/t65crop.t +++ b/t/t65crop.t @@ -1,6 +1,6 @@ #!perl -w use strict; -use Test::More tests => 60; +use Test::More tests => 64; require "t/testtools.pl"; use Imager; @@ -170,3 +170,13 @@ SKIP: cmp_ok($warning, '=~', 'void', "correct warning"); cmp_ok($warning, '=~', 't65crop\\.t', "correct file"); } + +{ + my $src = test_oo_img(); + ok(!$src->crop( top=>1000, bottom=>1500, left=>0, right=>100 ), + "outside of image" ); + cmp_ok($src->errstr, '=~', qr/outside of the image/, "and message"); + ok(!$src->crop( top=>100, bottom=>1500, left=>1000, right=>1500 ), + "outside of image" ); + cmp_ok($src->errstr, '=~', qr/outside of the image/, "and message"); +}