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

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