but no callers call i_map() in such a way that it can happen.
Add a belt-and-suspenders check.
only for the old API.) Coverity complained that this leaked, but
this could only occur with an invalid (NULL pointer) color object.
+ - the underlying implementation of the map() method could read before
+ the beginning on an allocated array if supplied with inconsistent
+ parameters, which Coverity complained about. No Imager code calls
+ that function with inconsistent parameters, but a
+ belt-and-suspenders check was added.
+
Imager 1.008 - 31 Dec 2018
============
if (!mask) return; /* nothing to do here */
- for(i=0; i<im->channels; i++)
+ for(i=0; i<im->channels; i++) {
if (mask & (1<<i)) {
if (minset == -1) minset = i;
maxset = i;
}
+ }
mm_log((1, "minset=%d maxset=%d\n", minset, maxset));
+ if (minset == -1)
+ return;
+
vals = mymalloc(sizeof(i_color) * im->xsize);
for (y = 0; y < im->ysize; ++y) {
#!perl -w
use strict;
-use Test::More tests => 10;
-use Imager::Test qw(is_image);
+use Test::More;
+use Imager::Test qw(is_image test_image);
-d "testout" or mkdir "testout";
ok($out, "map()");
is_image($out, $cmp, "test map output");
}
+
+{
+ # test with zero mask: coverity detected a bad channel index problem
+ # that only applies in this case
+ my $im = test_image();
+ $im->setmask(mask => 0x80);
+ is($im->getmask, 0x80, "check we set mask");
+ my @map = ( map int $_ / 2, 0 .. 255 );
+ my $out = $im->map(maps => [ (undef) x 3 ]);
+ ok($out, "map done");
+}
+
+done_testing();