File qtimageformats-TGA-handler-check-for-out-of-range-image-size.patch of Package libqt5-qtimageformats.9671

From 7cfe47a8fe2f987fb2a066a696fb3d9d0afe4d65 Mon Sep 17 00:00:00 2001
From: Eirik Aavitsland <eirik.aavitsland@qt.io>
Date: Fri, 24 Aug 2018 12:03:00 +0200
Subject: [PATCH] TGA handler: check for out of range image size

Make the decoder fail early to avoid spending time and memory on
attempting to decode a corrupt image file.

Change-Id: Iac35e72de743f412a65d11c58fe7faa275dc4e41
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
---
 src/plugins/imageformats/tga/qtgafile.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/plugins/imageformats/tga/qtgafile.cpp b/src/plugins/imageformats/tga/qtgafile.cpp
index 97510df..5d086c6 100644
--- a/src/plugins/imageformats/tga/qtgafile.cpp
+++ b/src/plugins/imageformats/tga/qtgafile.cpp
@@ -163,6 +163,12 @@ QTgaFile::QTgaFile(QIODevice *device)
     if (!validDepth)
     {
         mErrorMessage = tr("Image depth not valid");
+        return;
+    }
+    if (quint64(width()) * quint64(height()) > (8192 * 8192))
+    {
+        mErrorMessage = tr("Image size exceeds limit");
+        return;
     }
     int curPos = mDevice->pos();
     int fileBytes = mDevice->size();
@@ -233,6 +239,8 @@ QImage QTgaFile::readImage()
     unsigned char yCorner = desc & 0x20; // 0 = lower, 1 = upper
 
     QImage im(imageWidth, imageHeight, QImage::Format_ARGB32);
+    if (im.isNull())
+        return QImage();
     TgaReader *reader = 0;
     if (bitsPerPixel == 16)
         reader = new Tga16Reader();
-- 
2.16.4

openSUSE Build Service is sponsored by