Blame SOURCES/exiv2-additional-security-fixes.patch

240d3a
diff --git a/src/actions.cpp b/src/actions.cpp
240d3a
index 0ebe850..3cd398e 100644
240d3a
--- a/src/actions.cpp
240d3a
+++ b/src/actions.cpp
240d3a
@@ -59,6 +59,7 @@ EXIV2_RCSID("@(#) $Id$")
240d3a
 #include <ctime>
240d3a
 #include <cmath>
240d3a
 #include <cassert>
240d3a
+#include <stdexcept>
240d3a
 #include <sys/types.h>                  // for stat()
240d3a
 #include <sys/stat.h>                   // for stat()
240d3a
 #ifdef EXV_HAVE_UNISTD_H
240d3a
@@ -236,33 +237,43 @@ namespace Action {
240d3a
     }
240d3a
240d3a
     int Print::run(const std::string& path)
240d3a
-    try {
240d3a
-        path_ = path;
240d3a
-        int rc = 0;
240d3a
-        Exiv2::PrintStructureOption option = Exiv2::kpsNone ;
240d3a
-        switch (Params::instance().printMode_) {
240d3a
-            case Params::pmSummary:   rc = printSummary();     break;
240d3a
-            case Params::pmList:      rc = printList();        break;
240d3a
-            case Params::pmComment:   rc = printComment();     break;
240d3a
-            case Params::pmPreview:   rc = printPreviewList(); break;
240d3a
-            case Params::pmStructure: rc = printStructure(std::cout,Exiv2::kpsBasic)     ; break;
240d3a
-            case Params::pmRecursive: rc = printStructure(std::cout,Exiv2::kpsRecursive) ; break;
240d3a
-
240d3a
-            case Params::pmXMP:
240d3a
-                 option = option == Exiv2::kpsNone ? Exiv2::kpsXMP        : option;  // drop
240d3a
-            case Params::pmIccProfile:{
240d3a
-                 option = option == Exiv2::kpsNone ? Exiv2::kpsIccProfile : option;
240d3a
-                 _setmode(_fileno(stdout),O_BINARY);
240d3a
-                 rc = printStructure(std::cout,option);
240d3a
-            } break;
240d3a
+    {
240d3a
+        try {
240d3a
+            path_ = path;
240d3a
+            int rc = 0;
240d3a
+            Exiv2::PrintStructureOption option = Exiv2::kpsNone ;
240d3a
+            switch (Params::instance().printMode_) {
240d3a
+                case Params::pmSummary:   rc = printSummary();     break;
240d3a
+                case Params::pmList:      rc = printList();        break;
240d3a
+                case Params::pmComment:   rc = printComment();     break;
240d3a
+                case Params::pmPreview:   rc = printPreviewList(); break;
240d3a
+                case Params::pmStructure: rc = printStructure(std::cout,Exiv2::kpsBasic)     ; break;
240d3a
+                case Params::pmRecursive: rc = printStructure(std::cout,Exiv2::kpsRecursive) ; break;
240d3a
+
240d3a
+                case Params::pmXMP:
240d3a
+                    if (option == Exiv2::kpsNone)
240d3a
+                        option = Exiv2::kpsXMP;
240d3a
+                    // drop
240d3a
+                case Params::pmIccProfile:
240d3a
+                    if (option == Exiv2::kpsNone)
240d3a
+                        option = Exiv2::kpsIccProfile;
240d3a
+                    _setmode(_fileno(stdout),O_BINARY);
240d3a
+                    rc = printStructure(std::cout,option);
240d3a
+                    break;
240d3a
+            }
240d3a
+            return rc;
240d3a
         }
240d3a
-        return rc;
240d3a
-    }
240d3a
-    catch(const Exiv2::AnyError& e) {
240d3a
-        std::cerr << "Exiv2 exception in print action for file "
240d3a
-                  << path << ":\n" << e << "\n";
240d3a
-        return 1;
240d3a
-    } // Print::run
240d3a
+        catch(const Exiv2::AnyError& e) {
240d3a
+            std::cerr << "Exiv2 exception in print action for file "
240d3a
+                      << path << ":\n" << e << "\n";
240d3a
+            return 1;
240d3a
+        }
240d3a
+        catch(const std::overflow_error& e) {
240d3a
+            std::cerr << "std::overflow_error exception in print action for file "
240d3a
+                      << path << ":\n" << e.what() << "\n";
240d3a
+            return 1;
240d3a
+        }
240d3a
+    }
240d3a
240d3a
     int Print::printStructure(std::ostream& out, Exiv2::PrintStructureOption option)
240d3a
     {
240d3a
diff --git a/src/error.cpp b/src/error.cpp
240d3a
index e90a9c0..5d63957 100644
240d3a
--- a/src/error.cpp
240d3a
+++ b/src/error.cpp
240d3a
@@ -109,6 +109,8 @@ namespace {
240d3a
         { 55, N_("tiff directory length is too large") },
240d3a
         { 56, N_("invalid type value detected in Image::printIFDStructure") },
240d3a
         { 57, N_("invalid memory allocation request") },
240d3a
+        { 58, N_("corrupted image metadata") },
240d3a
+        { 59, N_("Arithmetic operation overflow") },
240d3a
     };
240d3a
240d3a
 }
240d3a
diff --git a/src/nikonmn.cpp b/src/nikonmn.cpp
240d3a
index 571ab80..34bf601 100644
240d3a
--- a/src/nikonmn.cpp
240d3a
+++ b/src/nikonmn.cpp
240d3a
@@ -299,6 +299,8 @@ namespace Exiv2 {
240d3a
                                                const Value& value,
240d3a
                                                const ExifData* exifData)
240d3a
     {
240d3a
+        if ( ! exifData ) return os << "undefined" ;
240d3a
+
240d3a
         if ( value.count() >= 9 ) {
240d3a
             ByteOrder bo = getKeyString("Exif.MakerNote.ByteOrder",exifData) == "MM" ? bigEndian : littleEndian;
240d3a
             byte      p[4];
240d3a
diff --git a/src/pentaxmn.cpp b/src/pentaxmn.cpp
240d3a
index 4fc38be..b22cb43 100644
240d3a
--- a/src/pentaxmn.cpp
240d3a
+++ b/src/pentaxmn.cpp
240d3a
@@ -1167,6 +1167,8 @@ namespace Exiv2 {
240d3a
240d3a
     std::ostream& PentaxMakerNote::printShutterCount(std::ostream& os, const Value& value, const ExifData* metadata)
240d3a
     {
240d3a
+        if ( ! metadata ) return os << "undefined" ;
240d3a
+
240d3a
         ExifData::const_iterator dateIt = metadata->findKey(
240d3a
                 ExifKey("Exif.PentaxDng.Date"));
240d3a
         if (dateIt == metadata->end()) {
240d3a
diff --git a/src/pngchunk.cpp b/src/pngchunk.cpp
240d3a
index da4ccd0..4dcca4d 100644
240d3a
--- a/src/pngchunk.cpp
240d3a
+++ b/src/pngchunk.cpp
240d3a
@@ -68,6 +68,8 @@ namespace Exiv2 {
240d3a
                                    int*           outWidth,
240d3a
                                    int*           outHeight)
240d3a
     {
240d3a
+        assert(data.size_ >= 8);
240d3a
+
240d3a
         // Extract image width and height from IHDR chunk.
240d3a
240d3a
         *outWidth  = getLong((const byte*)data.pData_,     bigEndian);
240d3a
diff --git a/src/pngimage.cpp b/src/pngimage.cpp
240d3a
index 11b4198..ed7399a 100644
240d3a
--- a/src/pngimage.cpp
240d3a
+++ b/src/pngimage.cpp
240d3a
@@ -441,7 +441,9 @@ namespace Exiv2 {
240d3a
 #ifdef DEBUG
240d3a
                     std::cout << "Exiv2::PngImage::readMetadata: Found IHDR chunk (length: " << dataOffset << ")\n";
240d3a
 #endif
240d3a
-                    PngChunk::decodeIHDRChunk(cdataBuf, &pixelWidth_, &pixelHeight_);
240d3a
+                    if (cdataBuf.size_ >= 8) {
240d3a
+                        PngChunk::decodeIHDRChunk(cdataBuf, &pixelWidth_, &pixelHeight_);
240d3a
+                    }
240d3a
                 }
240d3a
                 else if (!memcmp(cheaderBuf.pData_ + 4, "tEXt", 4))
240d3a
                 {
240d3a
diff --git a/src/tiffvisitor.cpp b/src/tiffvisitor.cpp
240d3a
index 74f8d07..fad39b6 100644
240d3a
--- a/src/tiffvisitor.cpp
240d3a
+++ b/src/tiffvisitor.cpp
240d3a
@@ -1493,6 +1493,11 @@ namespace Exiv2 {
240d3a
         }
240d3a
         p += 4;
240d3a
         uint32_t isize= 0; // size of Exif.Sony1.PreviewImage
240d3a
+
240d3a
+        if (count > std::numeric_limits<uint32_t>::max() / typeSize) {
240d3a
+            throw Error(59);
240d3a
+        }
240d3a
+
240d3a
         uint32_t size = typeSize * count;
240d3a
         uint32_t offset = getLong(p, byteOrder());
240d3a
         byte* pData = p;
240d3a
@@ -1536,7 +1541,9 @@ namespace Exiv2 {
240d3a
             }
240d3a
         }
240d3a
         Value::AutoPtr v = Value::create(typeId);
240d3a
-        assert(v.get());
240d3a
+        if (!v.get()) {
240d3a
+            throw Error(58);
240d3a
+        }
240d3a
         if ( !isize ) {
240d3a
         	v->read(pData, size, byteOrder());
240d3a
         } else {