Blame SOURCES/exiv2-CVE-2018-8976.patch

4a042c
diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp
4a042c
index 9afcb58..ca83f14 100644
4a042c
--- a/src/jpgimage.cpp
4a042c
+++ b/src/jpgimage.cpp
4a042c
@@ -34,6 +34,7 @@ EXIV2_RCSID("@(#) $Id$")
4a042c
 #include "image_int.hpp"
4a042c
 #include "error.hpp"
4a042c
 #include "futils.hpp"
4a042c
+#include "enforce.hpp"
4a042c
 
4a042c
 #ifdef WIN32
4a042c
 #include <windows.h>
4a042c
@@ -328,12 +329,14 @@ namespace Exiv2 {
4a042c
         int c = -1;
4a042c
         // Skips potential padding between markers
4a042c
         while ((c=io_->getb()) != 0xff) {
4a042c
-            if (c == EOF) return -1;
4a042c
+            if (c == EOF)
4a042c
+                return -1;
4a042c
         }
4a042c
 
4a042c
         // Markers can start with any number of 0xff
4a042c
         while ((c=io_->getb()) == 0xff) {
4a042c
-            if (c == EOF) return -2;
4a042c
+            if (c == EOF)
4a042c
+                return -2;
4a042c
         }
4a042c
         return c;
4a042c
     }
4a042c
@@ -564,85 +567,88 @@ namespace Exiv2 {
4a042c
      out << Internal::stringFormat("%8ld | 0xff%02x %-5s", \
4a042c
                              io_->tell()-2,marker,nm[marker].c_str())
4a042c
 
4a042c
-    void JpegBase::printStructure(std::ostream& out, PrintStructureOption option,int depth)
4a042c
+    void JpegBase::printStructure(std::ostream& out, PrintStructureOption option, int depth)
4a042c
     {
4a042c
-        if (io_->open() != 0) throw Error(9, io_->path(), strError());
4a042c
+        if (io_->open() != 0)
4a042c
+            throw Error(9, io_->path(), strError());
4a042c
         // Ensure that this is the correct image type
4a042c
         if (!isThisType(*io_, false)) {
4a042c
-            if (io_->error() || io_->eof()) throw Error(14);
4a042c
+            if (io_->error() || io_->eof())
4a042c
+                throw Error(14);
4a042c
             throw Error(15);
4a042c
         }
4a042c
 
4a042c
-        bool bPrint = option==kpsBasic || option==kpsRecursive;
4a042c
+        bool bPrint = option == kpsBasic || option == kpsRecursive;
4a042c
         Exiv2::Uint32Vector iptcDataSegs;
4a042c
 
4a042c
-        if ( bPrint || option == kpsXMP || option == kpsIccProfile || option == kpsIptcErase ) {
4a042c
+        if (bPrint || option == kpsXMP || option == kpsIccProfile || option == kpsIptcErase) {
4a042c
 
4a042c
             // nmonic for markers
4a042c
-            std::string nm[256] ;
4a042c
-            nm[0xd8]="SOI"  ;
4a042c
-            nm[0xd9]="EOI"  ;
4a042c
-            nm[0xda]="SOS"  ;
4a042c
-            nm[0xdb]="DQT"  ;
4a042c
-            nm[0xdd]="DRI"  ;
4a042c
-            nm[0xfe]="COM"  ;
4a042c
+            std::string nm[256];
4a042c
+            nm[0xd8] = "SOI";
4a042c
+            nm[0xd9] = "EOI";
4a042c
+            nm[0xda] = "SOS";
4a042c
+            nm[0xdb] = "DQT";
4a042c
+            nm[0xdd] = "DRI";
4a042c
+            nm[0xfe] = "COM";
4a042c
 
4a042c
             // 0xe0 .. 0xef are APPn
4a042c
             // 0xc0 .. 0xcf are SOFn (except 4)
4a042c
-            nm[0xc4]="DHT"  ;
4a042c
-            for ( int i = 0 ; i <= 15 ; i++ ) {
4a042c
+            nm[0xc4] = "DHT";
4a042c
+            for (int i = 0; i <= 15; i++) {
4a042c
                 char MN[10];
4a042c
-                sprintf(MN,"APP%d",i);
4a042c
-                nm[0xe0+i] = MN;
4a042c
-                if ( i != 4 ) {
4a042c
-                    sprintf(MN,"SOF%d",i);
4a042c
-                    nm[0xc0+i] = MN;
4a042c
+                sprintf(MN, "APP%d", i);
4a042c
+                nm[0xe0 + i] = MN;
4a042c
+                if (i != 4) {
4a042c
+                    sprintf(MN, "SOF%d", i);
4a042c
+                    nm[0xc0 + i] = MN;
4a042c
                 }
4a042c
             }
4a042c
 
4a042c
             // which markers have a length field?
4a042c
             bool mHasLength[256];
4a042c
-            for ( int i = 0 ; i < 256 ; i ++ )
4a042c
-                mHasLength[i]
4a042c
-                  =   ( i >= sof0_ && i <= sof15_)
4a042c
-                  ||  ( i >= app0_ && i <= (app0_ | 0x0F))
4a042c
-                  ||  ( i == dht_  || i == dqt_ || i == dri_ || i == com_ || i == sos_ )
4a042c
-                  ;
4a042c
+            for (int i = 0; i < 256; i++)
4a042c
+                mHasLength[i] = (i >= sof0_ && i <= sof15_) || (i >= app0_ && i <= (app0_ | 0x0F)) ||
4a042c
+                                (i == dht_ || i == dqt_ || i == dri_ || i == com_ || i == sos_);
4a042c
 
4a042c
             // Container for the signature
4a042c
-            bool        bExtXMP    = false;
4a042c
-            long        bufRead    =  0;
4a042c
-            const long  bufMinSize = 36;
4a042c
-            DataBuf     buf(bufMinSize);
4a042c
+            bool bExtXMP = false;
4a042c
+            long bufRead = 0;
4a042c
+            const long bufMinSize = 36;
4a042c
+            DataBuf buf(bufMinSize);
4a042c
 
4a042c
             // Read section marker
4a042c
             int marker = advanceToMarker();
4a042c
-            if (marker < 0) throw Error(15);
4a042c
+            if (marker < 0)
4a042c
+                throw Error(15);
4a042c
 
4a042c
-            bool    done = false;
4a042c
-            bool    first= true;
4a042c
+            bool done = false;
4a042c
+            bool first = true;
4a042c
             while (!done) {
4a042c
                 // print marker bytes
4a042c
-                if ( first && bPrint ) {
4a042c
+                if (first && bPrint) {
4a042c
                     out << "STRUCTURE OF JPEG FILE: " << io_->path() << std::endl;
4a042c
-                    out << " address | marker       |  length | data" << std::endl ;
4a042c
+                    out << " address | marker       |  length | data" << std::endl;
4a042c
                     REPORT_MARKER;
4a042c
                 }
4a042c
-                first    = false;
4a042c
+                first = false;
4a042c
                 bool bLF = bPrint;
4a042c
 
4a042c
                 // Read size and signature
4a042c
                 std::memset(buf.pData_, 0x0, buf.size_);
4a042c
                 bufRead = io_->read(buf.pData_, bufMinSize);
4a042c
-                if (io_->error()) throw Error(14);
4a042c
-                if (bufRead < 2) throw Error(15);
4a042c
-                uint16_t size = mHasLength[marker] ? getUShort(buf.pData_, bigEndian) : 0 ;
4a042c
-                if ( bPrint &&  mHasLength[marker] ) out << Internal::stringFormat(" | %7d ", size);
4a042c
+                if (io_->error())
4a042c
+                    throw Error(14);
4a042c
+                if (bufRead < 2)
4a042c
+                    throw Error(15);
4a042c
+                uint16_t size = mHasLength[marker] ? getUShort(buf.pData_, bigEndian) : 0;
4a042c
+                if (bPrint && mHasLength[marker])
4a042c
+                    out << Internal::stringFormat(" | %7d ", size);
4a042c
 
4a042c
                 // print signature for APPn
4a042c
                 if (marker >= app0_ && marker <= (app0_ | 0x0F)) {
4a042c
                     // http://www.adobe.com/content/dam/Adobe/en/devnet/xmp/pdfs/XMPSpecificationPart3.pdf p75
4a042c
-                    const char* signature = (const char*) buf.pData_+2;
4a042c
+                    const char* signature = (const char*)buf.pData_ + 2;
4a042c
 
4a042c
                     // 728 rmills@rmillsmbp:~/gnu/exiv2/ttt $ exiv2 -pS test/data/exiv2-bug922.jpg
4a042c
                     // STRUCTURE OF JPEG FILE: test/data/exiv2-bug922.jpg
4a042c
@@ -651,13 +657,13 @@ namespace Exiv2 {
4a042c
                     //       2 | 0xe1 APP1  |     911 | Exif..MM.*.......%.........#....
4a042c
                     //     915 | 0xe1 APP1  |     870 | http://ns.adobe.com/xap/1.0/.
4a042c
                     //    1787 | 0xe1 APP1  |   65460 | http://ns.adobe.com/xmp/extensio
4a042c
-                    if ( option == kpsXMP && std::string(signature).find("http://ns.adobe.com/x")== 0 ) {
4a042c
+                    if (option == kpsXMP && std::string(signature).find("http://ns.adobe.com/x") == 0) {
4a042c
                         // extract XMP
4a042c
-                        if ( size > 0 ) {
4a042c
-                            io_->seek(-bufRead , BasicIo::cur);
4a042c
-                            byte* xmp  = new byte[size+1];
4a042c
-                            io_->read(xmp,size);
4a042c
-                            int start = 0 ;
4a042c
+                        if (size > 0) {
4a042c
+                            io_->seek(-bufRead, BasicIo::cur);
4a042c
+                            byte* xmp = new byte[size + 1];
4a042c
+                            io_->read(xmp, size);
4a042c
+                            int start = 0;
4a042c
 
4a042c
                             // http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/xmp/pdfs/XMPSpecificationPart3.pdf
4a042c
                             // if we find HasExtendedXMP, set the flag and ignore this block
4a042c
@@ -666,79 +672,80 @@ namespace Exiv2 {
4a042c
                             // we could implement out of sequence with a dictionary of sequence/offset
4a042c
                             // and dumping the XMP in a post read operation similar to kpsIptcErase
4a042c
                             // for the moment, dumping 'on the fly' is working fine
4a042c
-                            if ( ! bExtXMP ) {
4a042c
-                                while (xmp[start]) start++;
4a042c
+                            if (!bExtXMP) {
4a042c
+                                while (xmp[start])
4a042c
+                                    start++;
4a042c
                                 start++;
4a042c
-                                if ( ::strstr((char*)xmp+start,"HasExtendedXMP") ) {
4a042c
-                                    start  = size ; // ignore this packet, we'll get on the next time around
4a042c
+                                if (::strstr((char*)xmp + start, "HasExtendedXMP")) {
4a042c
+                                    start = size;  // ignore this packet, we'll get on the next time around
4a042c
                                     bExtXMP = true;
4a042c
                                 }
4a042c
                             } else {
4a042c
-                                start = 2+35+32+4+4; // Adobe Spec, p19
4a042c
+                                start = 2 + 35 + 32 + 4 + 4;  // Adobe Spec, p19
4a042c
                             }
4a042c
 
4a042c
-                            out.write((const char*)(xmp+start),size-start);
4a042c
-                            delete [] xmp;
4a042c
+                            out.write((const char*)(xmp + start), size - start);
4a042c
+                            delete[] xmp;
4a042c
                             bufRead = size;
4a042c
                             done = !bExtXMP;
4a042c
                         }
4a042c
-                    } else if ( option == kpsIccProfile && std::strcmp(signature,iccId_) == 0 ) {
4a042c
+                    } else if (option == kpsIccProfile && std::strcmp(signature, iccId_) == 0) {
4a042c
                         // extract ICCProfile
4a042c
-                        if ( size > 0 ) {
4a042c
-                            io_->seek(-bufRead, BasicIo::cur); // back to buffer (after marker)
4a042c
-                            io_->seek(    14+2, BasicIo::cur); // step over header
4a042c
-                            DataBuf   icc(size-(14+2));
4a042c
-                            io_->read(             icc.pData_,icc.size_);
4a042c
-                            out.write((const char*)icc.pData_,icc.size_);
4a042c
+                        if (size > 0) {
4a042c
+                            io_->seek(-bufRead, BasicIo::cur);  // back to buffer (after marker)
4a042c
+                            io_->seek(14 + 2, BasicIo::cur);    // step over header
4a042c
+                            DataBuf icc(size - (14 + 2));
4a042c
+                            io_->read(icc.pData_, icc.size_);
4a042c
+                            out.write((const char*)icc.pData_, icc.size_);
4a042c
 #ifdef DEBUG
4a042c
                             std::cout << "iccProfile size = " << icc.size_ << std::endl;
4a042c
 #endif
4a042c
                             bufRead = size;
4a042c
                         }
4a042c
-                    } else if ( option == kpsIptcErase && std::strcmp(signature,"Photoshop 3.0") == 0 ) {
4a042c
+                    } else if (option == kpsIptcErase && std::strcmp(signature, "Photoshop 3.0") == 0) {
4a042c
                         // delete IPTC data segment from JPEG
4a042c
-                        if ( size > 0 ) {
4a042c
-                            io_->seek(-bufRead , BasicIo::cur);
4a042c
+                        if (size > 0) {
4a042c
+                            io_->seek(-bufRead, BasicIo::cur);
4a042c
                             iptcDataSegs.push_back(io_->tell());
4a042c
                             iptcDataSegs.push_back(size);
4a042c
                         }
4a042c
-                    } else if ( bPrint ) {
4a042c
-                        out << "| " << Internal::binaryToString(buf,size>32?32:size,size>0?2:0);
4a042c
-                        if ( std::strcmp(signature,iccId_) == 0 ) {
4a042c
-                            int chunk  = (int) signature[12];
4a042c
-                            int chunks = (int) signature[13];
4a042c
-                            out << Internal::stringFormat(" chunk %d/%d",chunk,chunks);
4a042c
+                    } else if (bPrint) {
4a042c
+                        out << "| " << Internal::binaryToString(buf, size > 32 ? 32 : size, size > 0 ? 2 : 0);
4a042c
+                        if (std::strcmp(signature, iccId_) == 0) {
4a042c
+                            int chunk = (int)signature[12];
4a042c
+                            int chunks = (int)signature[13];
4a042c
+                            out << Internal::stringFormat(" chunk %d/%d", chunk, chunks);
4a042c
                         }
4a042c
                     }
4a042c
 
4a042c
                     // for MPF: http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/MPF.html
4a042c
                     // for FLIR: http://owl.phy.queensu.ca/~phil/exiftool/TagNames/FLIR.html
4a042c
-                    bool bFlir = option == kpsRecursive && marker == (app0_+1) && std::strcmp(signature,"FLIR")==0;
4a042c
-                    bool bExif = option == kpsRecursive && marker == (app0_+1) && std::strcmp(signature,"Exif")==0;
4a042c
-                    bool bMPF  = option == kpsRecursive && marker == (app0_+2) && std::strcmp(signature,"MPF")==0;
4a042c
-                    bool bPS   = option == kpsRecursive                        && std::strcmp(signature,"Photoshop 3.0")==0;
4a042c
-                    if( bFlir || bExif || bMPF || bPS ) {
4a042c
+                    bool bFlir = option == kpsRecursive && marker == (app0_ + 1) && std::strcmp(signature, "FLIR") == 0;
4a042c
+                    bool bExif = option == kpsRecursive && marker == (app0_ + 1) && std::strcmp(signature, "Exif") == 0;
4a042c
+                    bool bMPF = option == kpsRecursive && marker == (app0_ + 2) && std::strcmp(signature, "MPF") == 0;
4a042c
+                    bool bPS = option == kpsRecursive && std::strcmp(signature, "Photoshop 3.0") == 0;
4a042c
+                    if (bFlir || bExif || bMPF || bPS) {
4a042c
                         // extract Exif data block which is tiff formatted
4a042c
-                        if ( size > 0 ) {
4a042c
+                        if (size > 0) {
4a042c
                             out << std::endl;
4a042c
 
4a042c
                             // allocate storage and current file position
4a042c
-                            byte*    exif      = new byte[size];
4a042c
-                            uint32_t restore   = io_->tell();
4a042c
+                            byte* exif = new byte[size];
4a042c
+                            uint32_t restore = io_->tell();
4a042c
 
4a042c
                             // copy the data to memory
4a042c
-                            io_->seek(-bufRead , BasicIo::cur);
4a042c
-                            io_->read(exif,size);
4a042c
-                            uint32_t start     = std::strcmp(signature,"Exif")==0 ? 8 : 6;
4a042c
-                            uint32_t max       = (uint32_t) size -1;
4a042c
+                            io_->seek(-bufRead, BasicIo::cur);
4a042c
+                            io_->read(exif, size);
4a042c
+                            uint32_t start = std::strcmp(signature, "Exif") == 0 ? 8 : 6;
4a042c
+                            uint32_t max = (uint32_t)size - 1;
4a042c
 
4a042c
                             // is this an fff block?
4a042c
-                            if ( bFlir ) {
4a042c
-                                start = 0 ;
4a042c
+                            if (bFlir) {
4a042c
+                                start = 0;
4a042c
                                 bFlir = false;
4a042c
-                                while ( start < max ) {
4a042c
-                                    if ( std::strcmp((const char*)(exif+start),"FFF")==0 ) {
4a042c
-                                        bFlir = true ;
4a042c
+                                while (start < max) {
4a042c
+                                    if (std::strcmp((const char*)(exif + start), "FFF") == 0) {
4a042c
+                                        bFlir = true;
4a042c
                                         break;
4a042c
                                     }
4a042c
                                     start++;
4a042c
@@ -747,78 +754,90 @@ namespace Exiv2 {
4a042c
 
4a042c
                             // there is a header in FLIR, followed by a tiff block
4a042c
                             // Hunt down the tiff using brute force
4a042c
-                            if ( bFlir ) {
4a042c
+                            if (bFlir) {
4a042c
                                 // FLIRFILEHEAD* pFFF = (FLIRFILEHEAD*) (exif+start) ;
4a042c
-                                while ( start < max ) {
4a042c
-                                    if ( exif[start] == 'I' && exif[start+1] == 'I' ) break;
4a042c
-                                    if ( exif[start] == 'M' && exif[start+1] == 'M' ) break;
4a042c
+                                while (start < max) {
4a042c
+                                    if (exif[start] == 'I' && exif[start + 1] == 'I')
4a042c
+                                        break;
4a042c
+                                    if (exif[start] == 'M' && exif[start + 1] == 'M')
4a042c
+                                        break;
4a042c
                                     start++;
4a042c
                                 }
4a042c
-                                if ( start < max ) std::cout << "  FFF start = " << start << std::endl ;
4a042c
+                                if ( start < max )
4a042c
+                                    std::cout << "  FFF start = " << start << std::endl;
4a042c
                                 // << " index = " << pFFF->dwIndexOff << std::endl;
4a042c
                             }
4a042c
 
4a042c
-                            if ( bPS ) {
4a042c
-                                IptcData::printStructure(out,exif,size,depth);
4a042c
+                            if (bPS) {
4a042c
+                                IptcData::printStructure(out, exif, size, depth);
4a042c
                             } else {
4a042c
                                 // create a copy on write memio object with the data, then print the structure
4a042c
-                                BasicIo::AutoPtr p = BasicIo::AutoPtr(new MemIo(exif+start,size-start));
4a042c
-                                if ( start < max ) printTiffStructure(*p,out,option,depth);
4a042c
+                                BasicIo::AutoPtr p = BasicIo::AutoPtr(new MemIo(exif + start, size - start));
4a042c
+                                if (start < max)
4a042c
+                                    printTiffStructure(*p, out, option, depth);
4a042c
                             }
4a042c
 
4a042c
                             // restore and clean up
4a042c
-                            io_->seek(restore,Exiv2::BasicIo::beg);
4a042c
-                            delete [] exif;
4a042c
-                            bLF    = false;
4a042c
+                            io_->seek(restore, Exiv2::BasicIo::beg);
4a042c
+                            delete[] exif;
4a042c
+                            bLF = false;
4a042c
                         }
4a042c
                     }
4a042c
                 }
4a042c
 
4a042c
                 // print COM marker
4a042c
-                if ( bPrint && marker == com_ ) {
4a042c
-                    int n = (size-2)>32?32:size-2; // size includes 2 for the two bytes for size!
4a042c
-                    out << "| " << Internal::binaryToString(buf,n,2); // start after the two bytes
4a042c
+                if (bPrint && marker == com_) {
4a042c
+                    int n = (size - 2) > 32 ? 32 : size - 2;             // size includes 2 for the two bytes for size!
4a042c
+                    out << "| " << Internal::binaryToString(buf, n, 2);  // start after the two bytes
4a042c
                 }
4a042c
 
4a042c
                 // Skip the segment if the size is known
4a042c
-                if (io_->seek(size - bufRead, BasicIo::cur)) throw Error(14);
4a042c
+                if (io_->seek(size - bufRead, BasicIo::cur))
4a042c
+                    throw Error(14);
4a042c
 
4a042c
-                if ( bLF ) out << std::endl;
4a042c
+                if (bLF)
4a042c
+                    out << std::endl;
4a042c
 
4a042c
                 if (marker != sos_) {
4a042c
                     // Read the beginning of the next segment
4a042c
                     marker = advanceToMarker();
4a042c
+                    enforce(marker>=0, kerNoImageInInputData);
4a042c
                     REPORT_MARKER;
4a042c
                 }
4a042c
                 done |= marker == eoi_ || marker == sos_;
4a042c
-                if ( done && bPrint ) out << std::endl;
4a042c
+                if (done && bPrint)
4a042c
+                    out << std::endl;
4a042c
             }
4a042c
         }
4a042c
-        if ( option == kpsIptcErase && iptcDataSegs.size() ) {
4a042c
+        if (option == kpsIptcErase && iptcDataSegs.size()) {
4a042c
 #ifdef DEBUG
4a042c
             std::cout << "iptc data blocks: " << iptcDataSegs.size() << std::endl;
4a042c
-            uint32_t toggle = 0 ;
4a042c
-            for ( Uint32Vector_i i = iptcDataSegs.begin(); i != iptcDataSegs.end() ; i++ ) {
4a042c
-                std::cout << *i ;
4a042c
-                if ( toggle++ % 2 ) std::cout << std::endl; else std::cout << ' ' ;
4a042c
+            uint32_t toggle = 0;
4a042c
+            for (Uint32Vector_i i = iptcDataSegs.begin(); i != iptcDataSegs.end(); i++) {
4a042c
+                std::cout << *i;
4a042c
+                if (toggle++ % 2)
4a042c
+                    std::cout << std::endl;
4a042c
+                else
4a042c
+                    std::cout << ' ';
4a042c
             }
4a042c
 #endif
4a042c
-            uint32_t count  = (uint32_t) iptcDataSegs.size();
4a042c
+            uint32_t count = (uint32_t)iptcDataSegs.size();
4a042c
 
4a042c
             // figure out which blocks to copy
4a042c
-            uint64_t* pos = new uint64_t[count+2];
4a042c
-            pos[0]        = 0 ;
4a042c
+            uint64_t* pos = new uint64_t[count + 2];
4a042c
+            pos[0] = 0;
4a042c
             // copy the data that is not iptc
4a042c
             Uint32Vector_i it = iptcDataSegs.begin();
4a042c
-            for ( uint64_t  i = 0 ; i < count ; i++ ) {
4a042c
-                bool  bOdd  = (i%2)!=0;
4a042c
-                bool  bEven = !bOdd;
4a042c
-                pos[i+1]    = bEven ? *it : pos[i] + *it;
4a042c
+            for (uint64_t i = 0; i < count; i++) {
4a042c
+                bool bOdd = (i % 2) != 0;
4a042c
+                bool bEven = !bOdd;
4a042c
+                pos[i + 1] = bEven ? *it : pos[i] + *it;
4a042c
                 it++;
4a042c
             }
4a042c
-            pos[count+1] = io_->size() - pos[count];
4a042c
+            pos[count + 1] = io_->size() - pos[count];
4a042c
 #ifdef DEBUG
4a042c
-            for ( uint64_t i = 0 ; i < count+2 ; i++ ) std::cout << pos[i] << " " ;
4a042c
+            for (uint64_t i = 0; i < count + 2; i++)
4a042c
+                std::cout << pos[i] << " ";
4a042c
             std::cout << std::endl;
4a042c
 #endif
4a042c
             // $ dd bs=1 skip=$((0)) count=$((13164)) if=ETH0138028.jpg of=E1.jpg
4a042c
@@ -829,29 +848,30 @@ namespace Exiv2 {
4a042c
             // binary copy io_ to a temporary file
4a042c
             BasicIo::AutoPtr tempIo(new MemIo);
4a042c
 
4a042c
-            assert (tempIo.get() != 0);
4a042c
-            for ( uint64_t i = 0 ; i < (count/2)+1 ; i++ ) {
4a042c
-                uint64_t start  = pos[2*i]+2 ; // step JPG 2 byte marker
4a042c
-                if ( start == 2 ) start = 0  ; // read the file 2 byte SOI
4a042c
-                long length = (long) (pos[2*i+1] - start) ;
4a042c
-                if ( length ) {
4a042c
+            assert(tempIo.get() != 0);
4a042c
+            for (uint64_t i = 0; i < (count / 2) + 1; i++) {
4a042c
+                uint64_t start = pos[2 * i] + 2;  // step JPG 2 byte marker
4a042c
+                if (start == 2)
4a042c
+                    start = 0;  // read the file 2 byte SOI
4a042c
+                long length = (long)(pos[2 * i + 1] - start);
4a042c
+                if (length) {
4a042c
 #ifdef DEBUG
4a042c
-                    std::cout << start <<":"<< length << std::endl;
4a042c
+                    std::cout << start << ":" << length << std::endl;
4a042c
 #endif
4a042c
-                    io_->seek(start,BasicIo::beg);
4a042c
+                    io_->seek(start, BasicIo::beg);
4a042c
                     DataBuf buf(length);
4a042c
-                    io_->read(buf.pData_,buf.size_);
4a042c
-                    tempIo->write(buf.pData_,buf.size_);
4a042c
+                    io_->read(buf.pData_, buf.size_);
4a042c
+                    tempIo->write(buf.pData_, buf.size_);
4a042c
                 }
4a042c
             }
4a042c
-            delete [] pos;
4a042c
+            delete[] pos;
4a042c
 
4a042c
             io_->seek(0, BasicIo::beg);
4a042c
-            io_->transfer(*tempIo); // may throw
4a042c
+            io_->transfer(*tempIo);  // may throw
4a042c
             io_->seek(0, BasicIo::beg);
4a042c
             readMetadata();
4a042c
         }
4a042c
-    } // JpegBase::printStructure
4a042c
+    }  // JpegBase::printStructure
4a042c
 
4a042c
     void JpegBase::writeMetadata()
4a042c
     {