Rex Dieter aeb79b
From e50aa2252cdd5cb53eef7d8c4503c7edff634f68 Mon Sep 17 00:00:00 2001
Rex Dieter aeb79b
From: "Richard J. Moore" <rich@kde.org>
Rex Dieter aeb79b
Date: Tue, 24 Feb 2015 19:02:35 +0000
Rex Dieter aeb79b
Subject: [PATCH 137/138] Fix a division by zero when processing malformed BMP
Rex Dieter aeb79b
 files.
Rex Dieter aeb79b
Rex Dieter aeb79b
This fixes a division by 0 when processing a maliciously crafted BMP
Rex Dieter aeb79b
file. No impact beyond DoS.
Rex Dieter aeb79b
Rex Dieter aeb79b
Backport of 661f6bfd032dacc62841037732816a583640e187
Rex Dieter aeb79b
Rex Dieter aeb79b
Task-number: QTBUG-44547
Rex Dieter aeb79b
Change-Id: I43f06e752b11cb50669101460902a82b885ae618
Rex Dieter aeb79b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Rex Dieter aeb79b
---
Rex Dieter aeb79b
 src/gui/image/qbmphandler.cpp | 6 ++++++
Rex Dieter aeb79b
 1 file changed, 6 insertions(+)
Rex Dieter aeb79b
Rex Dieter aeb79b
diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp
Rex Dieter aeb79b
index b22e842..30fa9e0 100644
Rex Dieter aeb79b
--- a/src/gui/image/qbmphandler.cpp
Rex Dieter aeb79b
+++ b/src/gui/image/qbmphandler.cpp
Rex Dieter aeb79b
@@ -319,10 +319,16 @@ static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, int offset, int
Rex Dieter aeb79b
         }
Rex Dieter aeb79b
     } else if (comp == BMP_BITFIELDS && (nbits == 16 || nbits == 32)) {
Rex Dieter aeb79b
         red_shift = calc_shift(red_mask);
Rex Dieter aeb79b
+        if (((red_mask >> red_shift) + 1) == 0)
Rex Dieter aeb79b
+            return false;
Rex Dieter aeb79b
         red_scale = 256 / ((red_mask >> red_shift) + 1);
Rex Dieter aeb79b
         green_shift = calc_shift(green_mask);
Rex Dieter aeb79b
+        if (((green_mask >> green_shift) + 1) == 0)
Rex Dieter aeb79b
+            return false;
Rex Dieter aeb79b
         green_scale = 256 / ((green_mask >> green_shift) + 1);
Rex Dieter aeb79b
         blue_shift = calc_shift(blue_mask);
Rex Dieter aeb79b
+        if (((blue_mask >> blue_shift) + 1) == 0)
Rex Dieter aeb79b
+            return false;
Rex Dieter aeb79b
         blue_scale = 256 / ((blue_mask >> blue_shift) + 1);
Rex Dieter aeb79b
     } else if (comp == BMP_RGB && (nbits == 24 || nbits == 32)) {
Rex Dieter aeb79b
         blue_mask = 0x000000ff;
Rex Dieter aeb79b
-- 
Rex Dieter aeb79b
1.9.3
Rex Dieter aeb79b