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

4a042c
From 6ede8aa1975177705450abb816163f0b8d33a597 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: Fri, 6 Oct 2017 23:09:08 +0200
4a042c
Subject: Fix for CVE-2017-14860
4a042c
4a042c
A heap buffer overflow could occur in memcpy when icc.size_ is larger
4a042c
than data.size_ - pad, as then memcpy would read out of bounds of data.
4a042c
4a042c
This commit adds a sanity check to iccLength (= icc.size_): if it is
4a042c
larger than data.size_ - pad (i.e. an overflow would be caused) an
4a042c
exception is thrown.
4a042c
4a042c
This fixes #71.
4a042c
4a042c
diff --git a/src/jp2image.cpp b/src/jp2image.cpp
4a042c
index 1892fd43..09d023e2 100644
4a042c
--- a/src/jp2image.cpp
4a042c
+++ b/src/jp2image.cpp
4a042c
@@ -269,10 +269,15 @@ namespace Exiv2
4a042c
                             std::cout << "Exiv2::Jp2Image::readMetadata: "
4a042c
                                      << "Color data found" << std::endl;
4a042c
 #endif
4a042c
-                            long pad = 3 ; // 3 padding bytes 2 0 0
4a042c
+                            const long pad = 3 ; // 3 padding bytes 2 0 0
4a042c
                             DataBuf data(subBox.length+8);
4a042c
                             io_->read(data.pData_,data.size_);
4a042c
-                            long    iccLength = getULong(data.pData_+pad, bigEndian);
4a042c
+                            const long    iccLength = getULong(data.pData_+pad, bigEndian);
4a042c
+                            // subtracting pad from data.size_ is safe:
4a042c
+                            // size_ is at least 8 and pad = 3
4a042c
+                            if (iccLength > data.size_ - pad) {
4a042c
+                                throw Error(58);
4a042c
+			    }
4a042c
                             DataBuf icc(iccLength);
4a042c
                             ::memcpy(icc.pData_,data.pData_+pad,icc.size_);
4a042c
 #ifdef DEBUG