Fixes crash in bmp and ico image decoding
authorEirik Aavitsland <eirik.aavitsland@theqtcompany.com>
Wed, 11 Mar 2015 12:34:01 +0000 (13:34 +0100)
committerRaspbian forward porter <root@raspbian.org>
Sun, 14 Jun 2015 16:38:43 +0000 (16:38 +0000)
Fuzzing test revealed that for certain malformed bmp and ico files,
the handler would segfault.

Change-Id: I19d45145f31e7f808f7f6a1a1610270ea4159cbe
(cherry picked from qtbase/2adbbae5432aa9d8cc41c6fcf55c2e310d2d4078)
Reviewed-by: Richard J. Moore <rich@kde.org>
Gbp-Pq: Name fixes_crash_in_bmp_and_ico_image_decoder.patch

src/gui/image/qbmphandler.cpp
src/plugins/imageformats/ico/qicohandler.cpp

index b22e842202537384dacef41e24609ae829632102..0b9edf5cb47f8d5f2e2c16f95467cfad38970f7b 100644 (file)
@@ -472,12 +472,6 @@ static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, int offset, int
                             p = data + (h-y-1)*bpl;
                             break;
                         case 2:                        // delta (jump)
-                            // Protection
-                            if ((uint)x >= (uint)w)
-                                x = w-1;
-                            if ((uint)y >= (uint)h)
-                                y = h-1;
-
                             {
                                 quint8 tmp;
                                 d->getChar((char *)&tmp);
@@ -485,6 +479,13 @@ static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, int offset, int
                                 d->getChar((char *)&tmp);
                                 y += tmp;
                             }
+
+                            // Protection
+                            if ((uint)x >= (uint)w)
+                                x = w-1;
+                            if ((uint)y >= (uint)h)
+                                y = h-1;
+
                             p = data + (h-y-1)*bpl + x;
                             break;
                         default:                // absolute mode
index 1a8860532e741d15f2e7cc6b52fac72ccfdc990e..3c3476576799b7c47470037d98886806952e3209 100644 (file)
@@ -571,7 +571,7 @@ QImage ICOReader::iconAt(int index)
                 QImage::Format format = QImage::Format_ARGB32;
                 if (icoAttrib.nbits == 24)
                     format = QImage::Format_RGB32;
-                else if (icoAttrib.ncolors == 2)
+                else if (icoAttrib.ncolors == 2 && icoAttrib.depth == 1)
                     format = QImage::Format_Mono;
                 else if (icoAttrib.ncolors > 0)
                     format = QImage::Format_Indexed8;