Blame SOURCES/exiv2-wrong-brackets.patch

340e69
From 1e07c98dfcbd8ac10ee02088f08235f5e1700148 Mon Sep 17 00:00:00 2001
340e69
From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= <dan.cermak@cgc-instruments.com>
340e69
Date: Wed, 27 Sep 2017 23:38:49 +0200
340e69
Subject: Fixed wrong brackets: size*count + pad can overflow before the cast
340e69
340e69
=> Should fix #76 (most of the work has been done by Robin Mills in
340e69
   6e3855aed7ba8bb4731fc4087ca7f9078b2f3d97)
340e69
340e69
The problem with #76 is the contents of the 26th IFD, with the
340e69
following contents:
340e69
tag: 0x8649
340e69
type: 0x1
340e69
count: 0xffff ffff
340e69
offset: 0x4974
340e69
340e69
The issue is the size of count (uint32_t), as adding anything to it
340e69
causes an overflow. Especially the expression:
340e69
(size*count + pad+20)
340e69
results in an overflow and gives 20 as a result instead of
340e69
0x100000014, thus the condition in the if in the next line is false
340e69
and the program continues to run (until it crashes at io.read).
340e69
340e69
To properly account for the overflow, the brackets have to be removed,
340e69
as then the result is saved in the correctly sized type and not cast
340e69
after being calculated in the smaller type.
340e69
340e69
diff --git a/src/image.cpp b/src/image.cpp
340e69
index ec5b873e..199671b9 100644
340e69
--- a/src/image.cpp
340e69
+++ b/src/image.cpp
340e69
@@ -401,7 +401,7 @@ namespace Exiv2 {
340e69
                 // if ( offset > io.size() ) offset = 0; // Denial of service?
340e69
 
340e69
                 // #55 memory allocation crash test/data/POC8
340e69
-                long long allocate = (long long) (size*count + pad+20);
340e69
+                long long allocate = (long long) size*count + pad+20;
340e69
                 if ( allocate > (long long) io.size() ) {
340e69
                     throw Error(57);
340e69
                 }