(get_histogram): Quiet Coverity 1024386 "Out-of-bounds read".

This was a benign mis-diagnosis but added code to enforce against
buffer overflow.
This commit is contained in:
Bob Friesenhahn 2015-05-28 03:08:18 +00:00
parent 73dcb5ee75
commit a80995a42b
2 changed files with 13 additions and 4 deletions

View File

@ -2,6 +2,9 @@
* tools/tiffmedian.c (GetInputLine): Fix Coverity 1024795 "Nesting * tools/tiffmedian.c (GetInputLine): Fix Coverity 1024795 "Nesting
level does not match indentation". level does not match indentation".
(get_histogram): Quiet Coverity 1024386 "Out-of-bounds read".
This was a benign mis-diagnosis but added code to enforce against
buffer overflow.
* tools/tiffcrop.c (ROTATE_ANY): Fix Coverity 1294542 "Logical * tools/tiffcrop.c (ROTATE_ANY): Fix Coverity 1294542 "Logical
vs. bitwise operator". vs. bitwise operator".

View File

@ -1,4 +1,4 @@
/* $Id: tiffmedian.c,v 1.11 2015-05-28 02:25:11 bfriesen Exp $ */ /* $Id: tiffmedian.c,v 1.12 2015-05-28 03:08:18 bfriesen Exp $ */
/* /*
* Apply median cut on an image. * Apply median cut on an image.
@ -371,9 +371,15 @@ get_histogram(TIFF* in, Colorbox* box)
break; break;
inptr = inputline; inptr = inputline;
for (j = imagewidth; j-- > 0;) { for (j = imagewidth; j-- > 0;) {
red = *inptr++ >> COLOR_SHIFT; red = (*inptr++) & 0xff >> COLOR_SHIFT;
green = *inptr++ >> COLOR_SHIFT; green = (*inptr++) & 0xff >> COLOR_SHIFT;
blue = *inptr++ >> COLOR_SHIFT; blue = (*inptr++) & 0xff >> COLOR_SHIFT;
if ((red | green | blue) >= B_LEN) {
fprintf(stderr,
"Logic error. "
"Histogram array overflow!\n");
exit(-6);
}
if (red < box->rmin) if (red < box->rmin)
box->rmin = red; box->rmin = red;
if (red > box->rmax) if (red > box->rmax)