Blame SOURCES/exiv2-CVE-2017-17669.patch

340e69
From 06aa7ab69d0c4f3d14644bd84fc9d1346154430d 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: Mon, 22 Jan 2018 23:56:08 +0100
340e69
Subject: Fix out of bounds read in src/pngchunk_int.cpp by @brianmay
340e69
340e69
- consider that key is advanced by 8 bytes if stripHeader is true
340e69
  => length is reduced by same amount
340e69
  Fixed by adding offset to the check in the loop
340e69
- Rewrote loop so that keysize is checked before the next
340e69
  iteration (preventing an out of bounds read)
340e69
340e69
diff --git a/src/pngchunk.cpp b/src/pngchunk.cpp
340e69
index da4ccd01..b54bcdac 100644
340e69
--- a/src/pngchunk.cpp
340e69
+++ b/src/pngchunk.cpp
340e69
@@ -107,15 +107,17 @@ namespace Exiv2 {
340e69
     {
340e69
         // From a tEXt, zTXt, or iTXt chunk,
340e69
         // we get the key, it's a null terminated string at the chunk start
340e69
-        if (data.size_ <= (stripHeader ? 8 : 0)) throw Error(14);
340e69
-        const byte *key = data.pData_ + (stripHeader ? 8 : 0);
340e69
+        const int offset = stripHeader ? 8 : 0;
340e69
+        if (data.size_ <= offset) throw Error(14);
340e69
+        const byte *key = data.pData_ + offset;
340e69
 
340e69
         // Find null string at end of key.
340e69
         int keysize=0;
340e69
-        for ( ; key[keysize] != 0 ; keysize++)
340e69
+        while (key[keysize] != 0)
340e69
         {
340e69
+            keysize++;
340e69
             // look if keysize is valid.
340e69
-            if (keysize >= data.size_)
340e69
+            if (keysize+offset >= data.size_)
340e69
                 throw Error(14);
340e69
         }
340e69