]> git.imager.perl.org - imager.git/commitdiff
map() would corrupt a channel if there was a gap in the arrayref of channels.
authorTony Cook <tony@develop-help.com>
Mon, 7 Jan 2019 11:31:33 +0000 (22:31 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 7 Jan 2019 11:31:33 +0000 (22:31 +1100)
Changes
map.c
t/300-transform/060-map.t

diff --git a/Changes b/Changes
index c06e676c24783a2408a5c3dbd242a6ba4b8a0714..3c58eb5706b04193558c1d87299bbef67cdadfd5 100644 (file)
--- a/Changes
+++ b/Changes
@@ -5,6 +5,9 @@ General changes:
  - to_paletted() and make_palette() now fail (with an error in
    errstr()) if invalid quantization parameters are supplied.
 
  - to_paletted() and make_palette() now fail (with an error in
    errstr()) if invalid quantization parameters are supplied.
 
+ - map() would corrupt a channel if there was a gap in the arrayref of
+   channels.  Detected by Coverity.  CID 185300.
+
 Coverity finally finished a build[1], fix a few problems:
 
 High severity:
 Coverity finally finished a build[1], fix a few problems:
 
 High severity:
diff --git a/map.c b/map.c
index aedd0dffd230307ff240635a39d90bfe70ff074e..9ddc62f855ebce456f7dc1588320b340cd1681f1 100644 (file)
--- a/map.c
+++ b/map.c
@@ -63,7 +63,8 @@ i_map(i_img *im, unsigned char (*maps)[256], unsigned int mask) {
     i_glin(im, 0, im->xsize, y, vals);
     for (x = 0; x < im->xsize; ++x) {
       for(ch = minset; ch<=maxset; ch++) {
     i_glin(im, 0, im->xsize, y, vals);
     for (x = 0; x < im->xsize; ++x) {
       for(ch = minset; ch<=maxset; ch++) {
-       if (!maps[ch]) continue;
+       if (!(mask & (1 << ch)))
+         continue;
        vals[x].channel[ch] = maps[ch][vals[x].channel[ch]];
       }
     }
        vals[x].channel[ch] = maps[ch][vals[x].channel[ch]];
       }
     }
index d8d8a18f93ce7b07cf84340fa5a053c7eaee7e09..67a8744ee03baa7c754dc2a70e2c08ffe6f06ce3 100644 (file)
@@ -73,4 +73,14 @@ SKIP: {
   ok($out, "map done");
 }
 
   ok($out, "map done");
 }
 
+{ # CID 185300
+  # the check for whether a map() channel was used was incorrect
+  my @map1 = ( 0 .. 255 );
+  my $im = test_image;
+  my $cmp = test_image->copy;
+  ok($im->map(maps => [ \@map1, undef, \@map1 ]),
+     "map with gap in maps");
+  is_image($im, $cmp, "should be no changes");
+}
+
 done_testing();
 done_testing();