- Calling setpixel() with color set to [ 0, 0, 0 ] would crash with
authorTony Cook <tony@develop=help.com>
Wed, 19 Apr 2006 12:19:56 +0000 (12:19 +0000)
committerTony Cook <tony@develop=help.com>
Wed, 19 Apr 2006 12:19:56 +0000 (12:19 +0000)
Can't locate object method "new" via package "Imager::Color::Float" ...

- having the color parameter code create floating point colors could
cause other problems too, since most of the underlying functions can't
handle them, so removed the attempt to create float colors.

Fixes #18561

Imager.pm
MANIFEST
t/tr18561.t [new file with mode: 0644]
t/tr18561b.t [new file with mode: 0644]

index 5d2b47555062fb0ea3755f20fd9d274284ce0288..178b3021c5c76e0140054f68a7e2691f864c8cc1 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -534,12 +534,7 @@ sub _color {
         $result = Imager::Color->new(%$arg);
       }
       elsif ($copy =~ /^ARRAY\(/) {
-        if (grep $_ > 1, @$arg) {
-          $result = Imager::Color->new(@$arg);
-        }
-        else {
-          $result = Imager::Color::Float->new(@$arg);
-        }
+       $result = Imager::Color->new(@$arg);
       }
       else {
         $Imager::ERRSTR = "Not a color";
index d31885a377d7578efd6eada551859e4d0cee1a20..47aac1e4d48257d3bb11b268e3ea14cf85230c40 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -230,6 +230,8 @@ t/t91pod.t          Test POD with Test::Pod
 t/t92samples.t
 t/t93podcover.t        POD Coverage tests
 t/testtools.pl
+t/tr18561.t            Regression tests
+t/tr18561b.t
 tags.c
 testimg/209_yonge.jpg  Regression test: #17981
 testimg/bad1oflow.bmp   1-bit/pixel, overflow integer on 32-bit machines
diff --git a/t/tr18561.t b/t/tr18561.t
new file mode 100644 (file)
index 0000000..fb7264f
--- /dev/null
@@ -0,0 +1,21 @@
+#!perl -w
+# regression test for RT issue 18561
+# 
+use strict;
+use Test::More tests => 1;
+eval {
+  use Imager;
+  
+  my $i = Imager->new(
+          xsize => 50,
+         ysize => 50,
+  );
+  
+  $i->setpixel(
+       x => 10,
+       y => 10,
+       color => [0, 0, 0],
+  );
+};
+ok(!$@, "shouldn't crash")
+  or print "# $@\n";
diff --git a/t/tr18561b.t b/t/tr18561b.t
new file mode 100644 (file)
index 0000000..6b93389
--- /dev/null
@@ -0,0 +1,17 @@
+#!perl -w
+# variant on the code that produces 18561
+# the old _color() code could return floating colors in some cases
+# but in most cases the caller couldn't handle it
+use strict;
+use Test::More tests => 1;
+eval {
+  use Imager;
+  use Imager::Color::Float; # prevent the actual 18561 crash
+  my $i = Imager->new(
+         xsize => 50,
+         ysize => 50,
+  );
+  $i->line(x1 => 0, y1 => 0, x2 => 99, y2=>99, color => [ 0, 0, 0 ]);
+};
+ok(!$@, "shouldn't crash")
+  or print "# $@\n";