From: Tony Cook Date: Mon, 7 Jan 2019 11:31:33 +0000 (+1100) Subject: map() would corrupt a channel if there was a gap in the arrayref of channels. X-Git-Tag: v1.009~9 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/35ec3a876754c726ff47cb1fde9a0cf472d9c519 map() would corrupt a channel if there was a gap in the arrayref of channels. --- diff --git a/Changes b/Changes index c06e676c..3c58eb57 100644 --- 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. + - 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: diff --git a/map.c b/map.c index aedd0dff..9ddc62f8 100644 --- 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++) { - if (!maps[ch]) continue; + if (!(mask & (1 << ch))) + continue; vals[x].channel[ch] = maps[ch][vals[x].channel[ch]]; } } diff --git a/t/300-transform/060-map.t b/t/300-transform/060-map.t index d8d8a18f..67a8744e 100644 --- a/t/300-transform/060-map.t +++ b/t/300-transform/060-map.t @@ -73,4 +73,14 @@ SKIP: { 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();