Blame SOURCES/exiv2-CVE-2018-12264-CVE-2018-12265.patch

240d3a
diff --git a/src/preview.cpp b/src/preview.cpp
240d3a
index 69f8e01..d20de04 100644
240d3a
--- a/src/preview.cpp
240d3a
+++ b/src/preview.cpp
240d3a
@@ -37,6 +37,7 @@ EXIV2_RCSID("@(#) $Id$")
240d3a
 #include "preview.hpp"
240d3a
 #include "futils.hpp"
240d3a
 #include "enforce.hpp"
240d3a
+#include "safe_op.hpp"
240d3a
240d3a
 #include "image.hpp"
240d3a
 #include "cr2image.hpp"
240d3a
@@ -386,7 +387,7 @@ namespace {
240d3a
             return AutoPtr();
240d3a
240d3a
         if (loaderList_[id].imageMimeType_ &&
240d3a
-            std::string(loaderList_[id].imageMimeType_) != std::string(image.mimeType()))
240d3a
+            std::string(loaderList_[id].imageMimeType_) != image.mimeType())
240d3a
             return AutoPtr();
240d3a
240d3a
         AutoPtr loader = loaderList_[id].create_(id, image, loaderList_[id].parIdx_);
240d3a
@@ -548,7 +549,8 @@ namespace {
240d3a
             }
240d3a
         }
240d3a
240d3a
-        if (offset_ + size_ > static_cast<uint32_t>(image_.io().size())) return;
240d3a
+        if (Safe::add(offset_, size_) > static_cast<uint32_t>(image_.io().size()))
240d3a
+            return;
240d3a
240d3a
         valid_ = true;
240d3a
     }
240d3a
@@ -802,7 +804,7 @@ namespace {
240d3a
                     // this saves one copying of the buffer
240d3a
                     uint32_t offset = dataValue.toLong(0);
240d3a
                     uint32_t size = sizes.toLong(0);
240d3a
-                    if (offset + size <= static_cast<uint32_t>(io.size()))
240d3a
+                    if (Safe::add(offset, size) <= static_cast<uint32_t>(io.size()))
240d3a
                         dataValue.setDataArea(base + offset, size);
240d3a
                 }
240d3a
                 else {
240d3a
@@ -812,8 +814,8 @@ namespace {
240d3a
                     for (int i = 0; i < sizes.count(); i++) {
240d3a
                         uint32_t offset = dataValue.toLong(i);
240d3a
                         uint32_t size = sizes.toLong(i);
240d3a
-                        enforce(idxBuf + size < size_, kerCorruptedMetadata);
240d3a
-                        if (size!=0 && offset + size <= static_cast<uint32_t>(io.size()))
240d3a
+                        enforce(Safe::add(idxBuf, size) < size_, kerCorruptedMetadata);
240d3a
+                        if (size!=0 && Safe::add(offset, size) <= static_cast<uint32_t>(io.size()))
240d3a
                             memcpy(&buf.pData_[idxBuf], base + offset, size);
240d3a
                         idxBuf += size;
240d3a
                     }
240d3a
@@ -930,7 +932,7 @@ namespace {
240d3a
240d3a
     DataBuf decodeBase64(const std::string& src)
240d3a
     {
240d3a
-        const unsigned long srcSize = static_cast<const unsigned long>(src.size());
240d3a
+        const unsigned long srcSize = src.size();
240d3a
240d3a
         // create decoding table
240d3a
         unsigned long invalid = 64;