Fix potential array overrun of static due to sign bit expansion
authorNelson Ferreira <nelson.ferreira@ieee.org>
Wed, 14 Sep 2011 09:34:29 +0000 (05:34 -0400)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Wed, 14 Sep 2011 09:34:29 +0000 (05:34 -0400)
CID:141

src/ui/imgproc.c
src/ui/imgproc.h

index 0770941..dea767c 100644 (file)
@@ -58,9 +58,9 @@ get_histogram(quant_table * qt, unsigned char *pic,
        inptr = pic;
        for (i = 0; i < height; i++) {
                for (j = width; j-- > 0;) {
-                       red = *inptr++ >> COLOR_SHIFT;
-                       green = *inptr++ >> COLOR_SHIFT;
-                       blue = *inptr++ >> COLOR_SHIFT;
+                       red = (*inptr++ >> COLOR_SHIFT) & COLOR_MASK;
+                       green = (*inptr++ >> COLOR_SHIFT) & COLOR_MASK;
+                       blue = (*inptr++ >> COLOR_SHIFT) & COLOR_MASK;
                        if (red < box->rmin)
                                box->rmin = red;
                        if (red > box->rmax)
index 31c67e8..dbe8255 100644 (file)
@@ -35,6 +35,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 #define        C_LEN           (1L<<C_DEPTH)   /* # cells/color to use */
 
 #define        COLOR_SHIFT     (COLOR_DEPTH-B_DEPTH)
+#define COLOR_MASK      (B_LEN-1)
 
 typedef struct colorbox {
        struct colorbox *next, *prev;