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

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