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

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