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

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