[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:46:11 UTC 2017


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=4617dc3

The following commit has been merged in the master branch:
commit 4617dc37284bb14c15fb884a7252de7c2b8b8854
Author: Robin Mills <robin at clanmills.com>
Date:   Thu Jan 7 16:13:28 2016 +0000

    #1108 and #1074 -pC and -pR (print Color Profile, print Recursively) now work on png.
---
 src/exiv2.1                 |   6 +-
 src/pngimage.cpp            | 234 +++++++++++++++++++++++++++++---------------
 src/tiffimage.cpp           |  37 ++++---
 test/data/bugfixes-test.out | Bin 1849383 -> 1849505 bytes
 test/tiff-test.sh           |   2 +-
 5 files changed, 183 insertions(+), 96 deletions(-)

diff --git a/src/exiv2.1 b/src/exiv2.1
index c1bd8af..29050f2 100644
--- a/src/exiv2.1
+++ b/src/exiv2.1
@@ -3,7 +3,7 @@
 .\" First parameter, NAME, should be all caps
 .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
 .\" other parameters are allowed: see man(7), man(1)
-.TH EXIV2 1 "Jan 5, 2016"
+.TH EXIV2 1 "Jan 7, 2016"
 .\" Please adjust this date whenever revising the manpage.
 .\"
 .\" Some roff macros, for reference:
@@ -315,9 +315,9 @@ c : JPEG comment
 .br
 p : list available image previews, sorted by preview image size in pixels
 .br
-C : print image ICC Profile (jpg only)
+C : print image ICC Profile (jpg and png only)
 .br
-R : print image structure recursively (jpg, tiff only)
+R : print image structure recursively (jpg, png, tiff only)
 .br
 S : print image structure information (jpg, png, tiff only)
 .br
diff --git a/src/pngimage.cpp b/src/pngimage.cpp
index c1aab1b..1504a75 100644
--- a/src/pngimage.cpp
+++ b/src/pngimage.cpp
@@ -36,6 +36,7 @@ EXIV2_RCSID("@(#) $Id$")
 #include "pngchunk_int.hpp"
 #include "pngimage.hpp"
 #include "jpgimage.hpp"
+#include "tiffimage.hpp"
 #include "image.hpp"
 #include "image_int.hpp"
 #include "basicio.hpp"
@@ -94,47 +95,76 @@ namespace Exiv2 {
         return "image/png";
     }
 
-    static void zlibUncompress(const byte*  compressedText,
-                                  unsigned int compressedTextSize,
-                                  DataBuf&     arr)
+    static bool zlibToDataBuf(const byte* bytes,long length, DataBuf& result)
     {
-        uLongf uncompressedLen = compressedTextSize * 2; // just a starting point
-        int zlibResult;
-        int dos = 0;
+        uLongf uncompressedLen = length * 2; // just a starting point
+        int    zlibResult;
 
         do {
-            arr.alloc(uncompressedLen);
-            zlibResult = uncompress((Bytef*)arr.pData_,
-                                    &uncompressedLen,
-                                    compressedText,
-                                    compressedTextSize);
-            if (zlibResult == Z_OK) {
-                assert((uLongf)arr.size_ >= uncompressedLen);
-                arr.size_ = uncompressedLen;
-            }
-            else if (zlibResult == Z_BUF_ERROR) {
+            result.alloc(uncompressedLen);
+            zlibResult = uncompress((Bytef*)result.pData_,&uncompressedLen,bytes,length);
+            if (zlibResult == Z_BUF_ERROR) {
                 // the uncompressedArray needs to be larger
+                result.release();
+
+                // never bigger than 64k
+                if  (uncompressedLen > 64*1024) zlibResult = Z_DATA_ERROR;
                 uncompressedLen *= 2;
-                // DoS protection. can't be bigger than 64k
-                if (uncompressedLen > 131072) {
-                    if (++dos > 1) break;
-                    uncompressedLen = 131072;
-                }
             }
-            else {
-                // something bad happened
-                throw Error(14);
+        } while (zlibResult == Z_BUF_ERROR);
+
+        return zlibResult == Z_OK ;
+    }
+
+    static bool tEXtToDataBuf(const byte* bytes,long length,DataBuf& result)
+    {
+        static const char* hexdigits = "0123456789ABCDEF";
+        static int         value   [256] ;
+        static bool        bFirst = true ;
+        if ( bFirst ) {
+            for ( int i = 0 ; i < 256 ; i++ )
+                value[i] = 0;
+            for ( int i = 0 ; i < 16 ; i++ ) {
+                value[tolower(hexdigits[i])]=i+1;
+                value[toupper(hexdigits[i])]=i+1;
             }
+            bFirst = false;
         }
-        while (zlibResult == Z_BUF_ERROR);
 
-        if (zlibResult != Z_OK) {
-            throw Error(14);
+        // calculate length and allocate result;
+        long        count=0;
+        const byte* p = bytes ;
+        // header is 
something
 number
 hex
+        while ( count < 3 )
+            if ( *p++ == '
' )
+                count++;
+        for ( long i = 0 ; i < length ; i++ )
+            if ( value[p[i]] )
+                ++count;
+        result.alloc((count+1)/2) ;
+
+        // hex to binary
+        count   = 0 ;
+        byte* r = result.pData_;
+        int   n = 0 ; // nibble
+        for ( long i = 0 ; i < length ; i++ ) {
+            if ( value[p[i]] ) {
+                int v = value[p[i]]-1 ;
+                if ( ++count % 2 ) n = v*16 ; // leading digit
+                else *r++ =        n + v    ; // trailing
+            }
         }
+        return true;
     }
 
+    static std::string indent(int depth)
+    {
+        std::string result;
+        while ( depth -- ) result += "  ";
+        return result;
+    }
 
-    void PngImage::printStructure(std::ostream& out, PrintStructureOption option, int /*depth*/)
+    void PngImage::printStructure(std::ostream& out, PrintStructureOption option, int depth)
     {
         if (io_->open() != 0) {
             throw Error(9, io_->path(), strError());
@@ -146,17 +176,19 @@ namespace Exiv2 {
             throw Error(3, "PNG");
         }
 
-        if ( option == kpsRecursive || option == kpsIccProfile ) { // disable kpsIccProfile because decompress isn't working!
-        	throw Error(13, io_->path());
-        }
-
         char    chType[5];
         chType[0]=0;
         chType[4]=0;
 
-        if ( option == kpsBasic || option == kpsXMP || option == kpsIccProfile ) {
+        if ( option == kpsBasic || option == kpsXMP || option == kpsIccProfile || option == kpsRecursive ) {
 
-            if ( option == kpsBasic ) {
+            const std::string xmpKey  = "XML:com.adobe.xmp";
+            const std::string exifKey = "Raw profile type exif";
+            const std::string iptcKey = "Raw profile type iptc";
+            const std::string iccKey  = "icc";
+            const std::string softKey = "Software";
+
+            if ( option == kpsBasic || option == kpsRecursive ) {
                 out << "STRUCTURE OF PNG FILE: " << io_->path() << std::endl;
                 out << " address | index | chunk_type |  length | data" << std::endl;
             }
@@ -175,62 +207,106 @@ namespace Exiv2 {
 
                 // Decode chunk data length.
                 uint32_t dataOffset = Exiv2::getULong(cheaderBuf.pData_, Exiv2::bigEndian);
-                long pos = io_->tell();
-                if (   pos == -1
-                    || dataOffset > uint32_t(0x7FFFFFFF)
-                    || static_cast<long>(dataOffset) > imgSize - pos) throw Exiv2::Error(14);
-
                 for (int i = 4; i < 8; i++) {
                     chType[i-4]=cheaderBuf.pData_[i];
                 }
 
-                uint32_t    blen = 32   ;
-                uint32_t    dOff = dataOffset;
+                // test that we haven't hit EOF, or wanting to read excessive data
+                long restore = io_->tell();
+                if(  restore == -1
+                ||  dataOffset > uint32_t(0x7FFFFFFF)
+                ||  static_cast<long>(dataOffset) > imgSize - restore
+                ){
+                    throw Exiv2::Error(14);
+                }
+
+                // format output
+                uint32_t    blen = dataOffset > 32 ? 32 : dataOffset ;
                 std::string dataString ;
+                DataBuf buff(blen);
+                io_->read(buff.pData_,blen);
+                io_->seek(restore, BasicIo::beg);
+                dataString  = Internal::binaryToString(buff, blen);
+
+                if ( option == kpsBasic || option == kpsRecursive )
+                    out << Internal::stringFormat("%8d | %5d | %10s |%8d | "
+                              ,(uint32_t)address, index++,chType,dataOffset)
+                                    << dataString << std::endl;
+
+
+                // chunk type
+                bool tEXt  = std::strcmp(chType,"tEXt")== 0;
+                bool zTXt  = std::strcmp(chType,"zTXt")== 0;
+                bool iCCP  = std::strcmp(chType,"iCCP")== 0;
+                bool iTXt  = std::strcmp(chType,"iTXt")== 0;
+
+                // for XMP, ICC etc: read and format data
+                bool bXMP  = option == kpsXMP        && dataString.find(xmpKey)==0;
+                bool bICC  = option == kpsIccProfile && dataString.find(iccKey)==0;
+                bool bExif = option == kpsRecursive  && dataString.find(exifKey)==0;
+                bool bIptc = option == kpsRecursive  && dataString.find(iptcKey)==0;
+                bool bSoft = option == kpsRecursive  && dataString.find(softKey)==0;
+                bool bDump = bXMP || bICC || bExif || bIptc || bSoft ;
+
+                if( bDump ) {
+                    DataBuf   dataBuf;
+                    byte*     data   = new byte[dataOffset];
+                    io_->read(data,dataOffset);
+                    io_->seek(restore, BasicIo::beg);
+                    size_t     name_l = std::strlen((const char*)data)+1; // leading string length
+                    size_t     start  = name_l;
+
+                    // decode the chunk
+                    bool bGood = false;
+                    if ( tEXt ) {
+                        bGood = tEXtToDataBuf(data+name_l,dataOffset-name_l,dataBuf);
+                    }
+                    if ( zTXt || iCCP ) {
+                        name_l++ ; // +1 = 'compressed' flag
+                        bGood = zlibToDataBuf(data+name_l,dataOffset-name_l,dataBuf);
+                    }
+                    if ( iTXt ) {
+                        while ( data[start] == 0 && start < dataOffset ) start++; // crawl over the '

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list