]> git.imager.perl.org - imager.git/commitdiff
- check that the result of fileno($fh) is defined rather than simply
authorTony Cook <tony@develop=help.com>
Fri, 18 Apr 2008 04:36:55 +0000 (04:36 +0000)
committerTony Cook <tony@develop=help.com>
Fri, 18 Apr 2008 04:36:55 +0000 (04:36 +0000)
   true when read() or write() is supplied with an fh parameter.
   http://rt.cpan.org/Ticket/Display.html?id=35139

 - i_scale_axis() wasn't checking the result of i_img_new_ch()
   resulting in a SIGSEGV when attempting to scale an image to a size
   too large to fit in memory.  This is a NULL pointer access issue,
   not a buffer overflow.
   Added a check for the failure.
   scale_calculate() (and hence scale()) will now fail if any of the
   scale size parameters are a reference.
   http://rt.cpan.org/Ticket/Display.html?id=35172

Changes
Imager.pm
image.c
t/t40scale.t

diff --git a/Changes b/Changes
index c994ade56ad013bc2510a146d4c311399d403bde..e6ef2bfd4af3b4489b5c59ae7e4139085e899062 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,23 @@
 Imager release history.  Older releases can be found in Changes.old
 
+Imager 0.64 - unreleased
+===========
+
+Bug fixes:
+
+ - check that the result of fileno($fh) is defined rather than simply
+   true when read() or write() is supplied with an fh parameter.
+   http://rt.cpan.org/Ticket/Display.html?id=35139
+
+ - i_scale_axis() wasn't checking the result of i_img_new_ch()
+   resulting in a SIGSEGV when attempting to scale an image to a size
+   too large to fit in memory.  This is a NULL pointer access issue,
+   not a buffer overflow.
+   Added a check for the failure.
+   scale_calculate() (and hence scale()) will now fail if any of the
+   scale size parameters are a reference.
+   http://rt.cpan.org/Ticket/Display.html?id=35172
+
 Imager 0.63 - 7 April 2008
 ===========
 
index 7c9c12ccd145170a84c8f2bca4fe088733f53c8d..446bd22c6306c33e331184ac0b1b763467889308 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -1197,7 +1197,7 @@ sub _get_reader_io {
   }
   elsif ($input->{fh}) {
     my $fd = fileno($input->{fh});
-    unless ($fd) {
+    unless (defined $fd) {
       $self->_set_error("Handle in fh option not opened");
       return;
     }
@@ -1248,7 +1248,7 @@ sub _get_writer_io {
   }
   elsif ($input->{fh}) {
     my $fd = fileno($input->{fh});
-    unless ($fd) {
+    unless (defined $fd) {
       $self->_set_error("Handle in fh option not opened");
       return;
     }
@@ -2075,6 +2075,14 @@ sub scale_calculate {
 
   my %opts = ('type'=>'max', @_);
 
+  # none of these should be references
+  for my $name (qw/xpixels ypixels xscalefactor yscalefactor width height/) {
+    if (defined $opts{$name} && ref $opts{$name}) {
+      $self->_set_error("scale_calculate: $name parameter cannot be a reference");
+      return;
+    }
+  }
+
   my ($x_scale, $y_scale);
   my $width = $opts{width};
   my $height = $opts{height};
@@ -2178,12 +2186,12 @@ sub scale {
   if ($opts{qtype} eq 'normal') {
     $tmp->{IMG} = i_scaleaxis($self->{IMG}, $x_scale, 0);
     if ( !defined($tmp->{IMG}) ) { 
-      $self->{ERRSTR} = 'unable to scale image';
+      $self->{ERRSTR} = 'unable to scale image: ' . $self->_error_as_msg;
       return undef;
     }
     $img->{IMG}=i_scaleaxis($tmp->{IMG}, $y_scale, 1);
     if ( !defined($img->{IMG}) ) { 
-      $self->{ERRSTR}='unable to scale image'
+      $self->{ERRSTR}='unable to scale image: ' . $self->_error_as_msg
       return undef;
     }
 
@@ -2200,7 +2208,7 @@ sub scale {
   elsif ($opts{'qtype'} eq 'mixing') {
     $img->{IMG} = i_scale_mixing($self->{IMG}, $new_width, $new_height);
     unless ($img->{IMG}) {
-      $self->_set_error(Imager->_error_as_meg);
+      $self->_set_error(Imager->_error_as_msg);
       return;
     }
     return $img;
diff --git a/image.c b/image.c
index 27382f6665bafa4c3bb6a43ef53049bcd786ae70..5dba629f32ba0b8430775ce4698009de2cfe414c 100644 (file)
--- a/image.c
+++ b/image.c
@@ -853,6 +853,7 @@ i_scaleaxis(i_img *im, float Value, int Axis) {
   i_color val,val1,val2;
   i_img *new_img;
 
+  i_clear_error();
   mm_log((1,"i_scaleaxis(im %p,Value %.2f,Axis %d)\n",im,Value,Axis));
 
 
@@ -880,6 +881,10 @@ i_scaleaxis(i_img *im, float Value, int Axis) {
   }
   
   new_img = i_img_empty_ch(NULL, hsize, vsize, im->channels);
+  if (!new_img) {
+    i_push_error(0, "cannot create output image");
+    return NULL;
+  }
   
   /* 1.4 is a magic number, setting it to 2 will cause rather blurred images */
   LanczosWidthFactor = (Value >= 1) ? 1 : (int) (1.4/Value); 
index f4de640804145bb5e49bbc589aff0c12ab5a7926..4ffcc25e51a037dca1ca88c23d31a4aa2a48fac1 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 228;
+use Test::More tests => 230;
 
 BEGIN { use_ok(Imager=>':all') }
 use Imager::Test qw(is_image is_color4);
@@ -213,6 +213,14 @@ SKIP:
            "class method scale_factor");
 }
 
+{ # passing a reference for scaling parameters should fail
+  # RT #35172
+  my $im = Imager->new(xsize => 100, ysize => 100);
+  ok(!$im->scale(xpixels => {}), "can't use a reference as a size");
+  cmp_ok($im->errstr, '=~', "xpixels parameter cannot be a reference",
+        "check error message");
+}
+
 sub scale_test {
   my ($in, $method, $exp_width, $exp_height, $note, @parms) = @_;