[PATCH] Check for QImage allocation failure in qgifhandler
authorEirik Aavitsland <eirik.aavitsland@qt.io>
Fri, 3 Aug 2018 11:25:15 +0000 (13:25 +0200)
committerAdrian Bunk <bunk@debian.org>
Sun, 20 Sep 2020 19:01:50 +0000 (20:01 +0100)
Since image files easily can be (or corrupt files claim to be) huge,
it is worth checking for out of memory situations.

Change-Id: I635a3ec6852288079fdec4e14cf7e776fe59e9e0
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Gbp-Pq: Name CVE-2018-19870.patch

src/gui/image/qgifhandler.cpp

index 5ef1a4ac3ac6a0198070431d127b3d0a5a253559..9db38e8fd9e0e64f17f569e92a20b38e8dd41d13 100644 (file)
@@ -356,7 +356,8 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length,
                     (*image) = QImage(swidth, sheight, format);
                     bpl = image->bytesPerLine();
                     bits = image->bits();
-                    memset(bits, 0, image->byteCount());
+                    if (bits)
+                        memset(bits, 0, image->byteCount());
                 }
 
                 // Check if the previous attempt to create the image failed. If it
@@ -424,6 +425,10 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length,
                         backingstore = QImage(qMax(backingstore.width(), w),
                                               qMax(backingstore.height(), h),
                                               QImage::Format_RGB32);
+                        if (backingstore.isNull()) {
+                            state = Error;
+                            return -1;
+                        }
                         memset(bits, 0, image->byteCount());
                     }
                     const int dest_bpl = backingstore.bytesPerLine();