RT#128481: fix handling of GIF files with no images
authorTony Cook <tony@develop-help.com>
Tue, 12 Feb 2019 08:45:35 +0000 (19:45 +1100)
committerTony Cook <tony@develop-help.com>
Tue, 12 Feb 2019 08:45:35 +0000 (19:45 +1100)
GIF/imgif.c
GIF/t/t30fixed.t

index da90b01d0270566c28eb15fc0ce95c8e255c701c..7a7fdb2bbae1a4fce9d5f578da230498f548b2ea 100644 (file)
@@ -905,6 +905,12 @@ i_readgif_multi_low(GifFileType *GifFile, int *count, int page) {
     return NULL;
   }
 
+  if (!ImageNum) {
+    /* there were no images */
+    i_push_error(0, "no images found in file");
+    return NULL;
+  }
+
   if (ImageNum && page != -1) {
     /* there were images, but the page selected wasn't found */
     i_push_errorf(0, "page %d not found (%d total)", page, ImageNum);
index 30b6965b480f02804207ae647e56d90ba9a5ee00..fbc9ed4badc6985365a5d4ae2355522a1109c9c7 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 9;
+use Test::More;
 use Imager;
 use Imager::Test qw(test_image);
 
@@ -44,4 +44,14 @@ Imager->open_log(log => "testout/t30fixed.log");
   is($rd->colorcount, 2, "should only have 2 colors");
 }
 
+{
+  my $im = Imager->new;
+  ok(!$im->read(data => "GIF89a;;;;;;;;", type => "gif" ),
+     "fail to read a file with no images");
+  like($im->errstr, qr/no images found in file/,
+       "check the error message");
+}
+
 Imager->close_log;
+
+done_testing();