diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 05c5ecff..456d952f 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -604,6 +604,19 @@ namespace Exiv2 { } } + // which markers have a length field? + bool mHasLength[256]; + for ( int marker = 0 ; marker < 256 ; marker ++ ) + mHasLength[marker] + = ( marker >= sof0_ && marker <= sof15_) + || ( marker >= app0_ && marker <= (app0_ | 0x0F)) + || marker == dht_ + || marker == dqt_ + || marker == dri_ + || marker == com_ + || marker == sos_ + ; + // Container for the signature bool bExtXMP = false; long bufRead = 0; @@ -631,27 +644,10 @@ namespace Exiv2 { bufRead = io_->read(buf.pData_, bufMinSize); if (io_->error()) throw Error(14); if (bufRead < 2) throw Error(15); - uint16_t size = 0; - - // not all markers have size field. - if( ( marker >= sof0_ && marker <= sof15_) - || ( marker >= app0_ && marker <= (app0_ | 0x0F)) - || marker == dht_ - || marker == dqt_ - || marker == dri_ - || marker == com_ - || marker == sos_ - ){ - size = getUShort(buf.pData_, bigEndian); - } - if ( bPrint ) out << Internal::stringFormat(" | %7d ", size); - if ( bPrint && marker == com_ ) { - int n = size>32?32:size; - if (n>3) n-=3; // three trailing bytes in a com - out << "| " << Internal::binaryToString(buf,n,2); - } + uint16_t size = mHasLength[marker] ? getUShort(buf.pData_, bigEndian) : 0 ; + if ( bPrint && mHasLength[marker] ) out << Internal::stringFormat(" | %7d ", size); - // only print the signature for appn + // print signature for APPn if (marker >= app0_ && marker <= (app0_ | 0x0F)) { // http://www.adobe.com/content/dam/Adobe/en/devnet/xmp/pdfs/XMPSpecificationPart3.pdf p75 const char* signature = (const char*) buf.pData_+2; @@ -696,13 +692,12 @@ namespace Exiv2 { } else if ( option == kpsIccProfile && std::strcmp(signature,iccId_) == 0 ) { // extract ICCProfile if ( size > 0 ) { - io_->seek(-bufRead , BasicIo::cur); - byte* icc = new byte[size]; - io_->read(icc,size); - std::size_t start=16; - out.write( ((const char*)icc)+start,size-start); + io_->seek(-bufRead , BasicIo::cur); // back to buffer (after marker+size) + io_->seek( 16 , BasicIo::cur); // step over header + DataBuf icc(size-2-16); + io_->read( icc.pData_,icc.size_); + out.write((const char*)icc.pData_,icc.size_); bufRead = size; - delete [] icc; } } else if ( option == kpsIptcErase && std::strcmp(signature,"Photoshop 3.0") == 0 ) { // delete IPTC data segment from JPEG @@ -779,28 +774,28 @@ namespace Exiv2 { io_->seek(restore,Exiv2::BasicIo::beg); delete [] exif; bLF = false; - } } } + // print COM marker + if ( bPrint && marker == com_ ) { + int n = (size-2)>32?32:size-2; // size includes 2 for the two bytes for size! + out << "| " << Internal::binaryToString(buf,n,2); // start after the two bytes + } + // Skip the segment if the size is known if (io_->seek(size - bufRead, BasicIo::cur)) throw Error(14); if ( bLF ) out << std::endl; - if (marker == sos_) - // sos_ is immediately followed by entropy-coded data & eoi_ - done = true; - else { + if (marker != sos_) { // Read the beginning of the next segment marker = advanceToMarker(); REPORT_MARKER; - if ( marker == eoi_ ) { - if ( option == kpsBasic ) out << std::endl; - done = true; - } } + done = marker == eoi_ || marker == sos_; + if ( done ) out << std::endl; } } if ( option == kpsIptcErase && iptcDataSegs.size() ) { @@ -1097,7 +1092,7 @@ namespace Exiv2 { tmpBuf[0] = 0xff; tmpBuf[1] = app2_; - int chunk_size = 256*256-18 ; // leave bytes for marker and header + int chunk_size = 256*256-40 ; // leave bytes for marker and header int size = (int) iccProfile_.size_ ; int chunks = 1 + (size-1) / chunk_size ; if (iccProfile_.size_ > 256*chunk_size) throw Error(37, "IccProfile"); @@ -1106,8 +1101,10 @@ namespace Exiv2 { size -= bytes ; // write JPEG marker (2 bytes) - us2Data(tmpBuf + 2, 16 + bytes, bigEndian); - if (outIo.write(tmpBuf, 4) != 4) throw Error(21); // JPEG Marker + if (outIo.write(tmpBuf, 2) != 2) throw Error(21); // JPEG Marker + // write length (2 bytes). length includes the 2 bytes for the length + us2Data(tmpBuf + 2, 2+16+bytes, bigEndian); + if (outIo.write(tmpBuf+2, 2) != 2) throw Error(21); // JPEG Length // write the ICC_PROFILE header (16 bytes) char pad[4]; @@ -1115,8 +1112,8 @@ namespace Exiv2 { pad[1] = chunks; pad[2] = 0; pad[3] = 0; - outIo.write((const byte *) iccId_,(long) ::strlen(iccId_) + 1); - outIo.write((const byte *) pad, sizeof(pad)); + outIo.write((const byte *) iccId_,12); + outIo.write((const byte *) pad, 4); if (outIo.write(iccProfile_.pData_+ (chunk*chunk_size), bytes) != bytes) throw Error(21); if (outIo.error()) throw Error(21); diff --git a/test/data/bugfixes-test.out b/test/data/bugfixes-test.out index 27a428d4..c63a02c1 100644 Binary files a/test/data/bugfixes-test.out and b/test/data/bugfixes-test.out differ diff --git a/test/data/icc-test.out b/test/data/icc-test.out index ef149e00..9d2553c5 100644 --- a/test/data/icc-test.out +++ b/test/data/icc-test.out @@ -1,6 +1,6 @@ STRUCTURE OF JPEG FILE: Reagan.jpg address | marker | length | data - 0 | 0xffd8 SOI | 0 + 0 | 0xffd8 SOI 2 | 0xffe0 APP0 | 16 | JFIF.....,.,.... 20 | 0xffe1 APP1 | 5671 | Exif..MM.*...................... 5693 | 0xffed APP13 | 9594 | Photoshop 3.0.8BIM..........Z... @@ -11,62 +11,200 @@ STRUCTURE OF JPEG FILE: Reagan.jpg 25665 | 0xffc0 SOF0 | 17 25684 | 0xffdd DRI | 4 25690 | 0xffc4 DHT | 418 - 26110 | 0xffda SOS | 12 + 26110 | 0xffda SOS STRUCTURE OF JPEG FILE: Reagan.jpg address | marker | length | data - 0 | 0xffd8 SOI | 0 + 0 | 0xffd8 SOI 2 | 0xffe0 APP0 | 16 | JFIF.....,.,.... 20 | 0xffe1 APP1 | 5658 | Exif..MM.*...................... 5680 | 0xffe1 APP1 | 7024 | http://ns.adobe.com/xap/1.0/....... chunk 4/25 - 274858 | 0xffe2 APP2 | 65534 | ICC_PROFILE.....W8w;.QY2w$.gZ.wY chunk 5/25 - 340396 | 0xffe2 APP2 | 65534 | ICC_PROFILE.....Y1...]W.j....QlT chunk 6/25 - 405934 | 0xffe2 APP2 | 65534 | ICC_PROFILE......ik.....j;....h. chunk 7/25 - 471472 | 0xffe2 APP2 | 65534 | ICC_PROFILE.....a.r2GRW.M...Y.MX chunk 8/25 - 537010 | 0xffe2 APP2 | 65534 | ICC_PROFILE.....`...bs]...dDZ7.b chunk 9/25 - 602548 | 0xffe2 APP2 | 65534 | ICC_PROFILE.....d.}...f.z...hRv. chunk 10/25 - 668086 | 0xffe2 APP2 | 65534 | ICC_PROFILE.......y+...^yy....y. chunk 11/25 - 733624 | 0xffe2 APP2 | 65534 | ICC_PROFILE......v.-i.....kN...< chunk 12/25 - 799162 | 0xffe2 APP2 | 65534 | ICC_PROFILE......'Z.....M.....>. chunk 13/25 - 864700 | 0xffe2 APP2 | 65534 | ICC_PROFILE..................... chunk 14/25 - 930238 | 0xffe2 APP2 | 65534 | ICC_PROFILE........D..........". chunk 15/25 - 995776 | 0xffe2 APP2 | 65534 | ICC_PROFILE.......V[*+..7.,G..'. chunk 16/25 - 1061314 | 0xffe2 APP2 | 65534 | ICC_PROFILE......Z...G.....C.... chunk 17/25 - 1126852 | 0xffe2 APP2 | 65534 | ICC_PROFILE......2yg.Te....VG... chunk 18/25 - 1192390 | 0xffe2 APP2 | 65534 | ICC_PROFILE..................... chunk 19/25 - 1257928 | 0xffe2 APP2 | 65534 | ICC_PROFILE.....1.0.285.0.373.0. chunk 20/25 - 1323466 | 0xffe2 APP2 | 65534 | ICC_PROFILE.....0.260.0.271.0.27 chunk 21/25 - 1389004 | 0xffe2 APP2 | 65534 | ICC_PROFILE.....39.0.145.0.150.0 chunk 22/25 - 1454542 | 0xffe2 APP2 | 65534 | ICC_PROFILE......0.051.0.060.0.0 chunk 23/25 - 1520080 | 0xffe2 APP2 | 65534 | ICC_PROFILE......0.743.0.788.0.8 chunk 24/25 - 1585618 | 0xffe2 APP2 | 41184 | ICC_PROFILE......452.0.452.0.464 chunk 25/25 + 12706 | 0xffe2 APP2 | 3161 | ICC_PROFILE........HLino....mntr chunk 1/1 + 15869 | 0xffed APP13 | 9594 | Photoshop 3.0.8BIM..........Z... + 25465 | 0xffee APP14 | 14 | Adobe.d@...... + 25481 | 0xffdb DQT | 132 + 25615 | 0xfffe COM | 10 | abcdefg + 25627 | 0xffc0 SOF0 | 17 + 25646 | 0xffdd DRI | 4 + 25652 | 0xffc4 DHT | 418 + 26072 | 0xffda SOS +abcdefg +STRUCTURE OF JPEG FILE: Reagan.jpg + address | marker | length | data + 0 | 0xffd8 SOI + 2 | 0xffe0 APP0 | 16 | JFIF.....,.,.... + 20 | 0xffe1 APP1 | 5658 | Exif..MM.*...................... + 5680 | 0xffe1 APP1 | 7024 | http://ns.adobe.com/xap/1.0/.J... chunk 12/25 + 798898 | 0xffe2 APP2 | 65514 | ICC_PROFILE......X..up.......... chunk 13/25 + 864414 | 0xffe2 APP2 | 65514 | ICC_PROFILE..........<.......... chunk 14/25 + 929930 | 0xffe2 APP2 | 65514 | ICC_PROFILE................,...' chunk 15/25 + 995446 | 0xffe2 APP2 | 65514 | ICC_PROFILE.........g.....m%... chunk 16/25 + 1060962 | 0xffe2 APP2 | 65514 | ICC_PROFILE........s....xX.M..n. chunk 17/25 + 1126478 | 0xffe2 APP2 | 65514 | ICC_PROFILE..............0...... chunk 18/25 + 1191994 | 0xffe2 APP2 | 65514 | ICC_PROFILE..........(.n.B...... chunk 19/25 + 1257510 | 0xffe2 APP2 | 65514 | ICC_PROFILE.....0.0.282.0.282.0. chunk 20/25 + 1323026 | 0xffe2 APP2 | 65514 | ICC_PROFILE.....175.0.176.0.175. chunk 21/25 + 1388542 | 0xffe2 APP2 | 65514 | ICC_PROFILE.....103.0.114.0.126. chunk 22/25 + 1454058 | 0xffe2 APP2 | 65514 | ICC_PROFILE.....6.0.049.0.053.0. chunk 23/25 + 1519574 | 0xffe2 APP2 | 65514 | ICC_PROFILE......0.670.0.653.0.6 chunk 24/25 + 1585090 | 0xffe2 APP2 | 41714 | ICC_PROFILE.....09.0.584.0.555.0 chunk 25/25 1626806 | 0xffed APP13 | 9594 | Photoshop 3.0.8BIM..........Z... 1636402 | 0xffee APP14 | 14 | Adobe.d@...... 1636418 | 0xffdb DQT | 132 1636552 | 0xffc0 SOF0 | 17 1636571 | 0xffdd DRI | 4 1636577 | 0xffc4 DHT | 418 - 1636997 | 0xffda SOS | 12 + 1636997 | 0xffda SOS +STRUCTURE OF JPEG FILE: Reagan.jpg + address | marker | length | data + 0 | 0xffd8 SOI + 2 | 0xffe0 APP0 | 16 | JFIF.....,.,.... + 20 | 0xffe1 APP1 | 5658 | Exif..MM.*...................... + 5680 | 0xffe1 APP1 | 7024 | http://ns.adobe.com/xap/1.0/.J. chunk 12/25 + 798898 | 0xffe2 APP2 | 65514 | ICC_PROFILE........X..up........ chunk 13/25 + 864414 | 0xffe2 APP2 | 65514 | ICC_PROFILE............<........ chunk 14/25 + 929930 | 0xffe2 APP2 | 65514 | ICC_PROFILE..................,.. chunk 15/25 + 995446 | 0xffe2 APP2 | 65514 | ICC_PROFILE...........g.....m%.. chunk 16/25 + 1060962 | 0xffe2 APP2 | 65514 | ICC_PROFILE..........s....xX.M.. chunk 17/25 + 1126478 | 0xffe2 APP2 | 65514 | ICC_PROFILE................0.... chunk 18/25 + 1191994 | 0xffe2 APP2 | 65514 | ICC_PROFILE............(.n.B.... chunk 19/25 + 1257510 | 0xffe2 APP2 | 65514 | ICC_PROFILE.......0.0.282.0.282. chunk 20/25 + 1323026 | 0xffe2 APP2 | 65514 | ICC_PROFILE.......175.0.176.0.17 chunk 21/25 + 1388542 | 0xffe2 APP2 | 65514 | ICC_PROFILE.......103.0.114.0.12 chunk 22/25 + 1454058 | 0xffe2 APP2 | 65514 | ICC_PROFILE.......6.0.049.0.053. chunk 23/25 + 1519574 | 0xffe2 APP2 | 65514 | ICC_PROFILE........0.670.0.653.0 chunk 24/25 + 1585090 | 0xffe2 APP2 | 41715 | ICC_PROFILE.......09.0.584.0.555 chunk 25/25 + 1626807 | 0xffed APP13 | 9594 | Photoshop 3.0.8BIM..........Z... + 1636403 | 0xffee APP14 | 14 | Adobe.d@...... + 1636419 | 0xffdb DQT | 132 + 1636553 | 0xfffe COM | 10 | abcdefg + 1636565 | 0xffc0 SOF0 | 17 + 1636584 | 0xffdd DRI | 4 + 1636590 | 0xffc4 DHT | 418 + 1637010 | 0xffda SOS +abcdefg STRUCTURE OF JPEG FILE: Reagan.jpg address | marker | length | data - 0 | 0xffd8 SOI | 0 + 0 | 0xffd8 SOI + 2 | 0xffe0 APP0 | 16 | JFIF.....,.,.... + 20 | 0xffe1 APP1 | 5658 | Exif..MM.*...................... + 5680 | 0xffe1 APP1 | 7024 | http://ns.adobe.com/xap/1.0/. chunk 12/25 + 798898 | 0xffe2 APP2 | 65514 | ICC_PROFILE..........X..up...... chunk 13/25 + 864414 | 0xffe2 APP2 | 65514 | ICC_PROFILE..............<...... chunk 14/25 + 929930 | 0xffe2 APP2 | 65514 | ICC_PROFILE...................., chunk 15/25 + 995446 | 0xffe2 APP2 | 65514 | ICC_PROFILE.............g.....m% chunk 16/25 + 1060962 | 0xffe2 APP2 | 65514 | ICC_PROFILE............s....xX.M chunk 17/25 + 1126478 | 0xffe2 APP2 | 65514 | ICC_PROFILE..................0.. chunk 18/25 + 1191994 | 0xffe2 APP2 | 65514 | ICC_PROFILE..............(.n.B.. chunk 19/25 + 1257510 | 0xffe2 APP2 | 65514 | ICC_PROFILE.........0.0.282.0.28 chunk 20/25 + 1323026 | 0xffe2 APP2 | 65514 | ICC_PROFILE.........175.0.176.0. chunk 21/25 + 1388542 | 0xffe2 APP2 | 65514 | ICC_PROFILE.........103.0.114.0. chunk 22/25 + 1454058 | 0xffe2 APP2 | 65514 | ICC_PROFILE.........6.0.049.0.05 chunk 23/25 + 1519574 | 0xffe2 APP2 | 65514 | ICC_PROFILE..........0.670.0.653 chunk 24/25 + 1585090 | 0xffe2 APP2 | 41716 | ICC_PROFILE.........09.0.584.0.5 chunk 25/25 + 1626808 | 0xffed APP13 | 9594 | Photoshop 3.0.8BIM..........Z... + 1636404 | 0xffee APP14 | 14 | Adobe.d@...... + 1636420 | 0xffdb DQT | 132 + 1636554 | 0xffc0 SOF0 | 17 + 1636573 | 0xffdd DRI | 4 + 1636579 | 0xffc4 DHT | 418 + 1636999 | 0xffda SOS +STRUCTURE OF JPEG FILE: Reagan.jpg + address | marker | length | data + 0 | 0xffd8 SOI 2 | 0xffe0 APP0 | 16 | JFIF.....,.,.... 20 | 0xffe1 APP1 | 5658 | Exif..MM.*...................... 5680 | 0xffe1 APP1 | 7024 | http://ns.adobe.com/xap/1.0/.1..B.!..o.. ......].. EXIF | 12040 | 172614 | II*........................... . - XMP | 1677405 | 184662 | reagan_1.icc runTest exiv2 -eC --force $filename mv $iccname_ reagan_2.icc + test2120 copyTestFile big.icc $iccname_ runTest exiv2 -iC $filename @@ -23,19 +33,24 @@ source ./functions.source runTest exiv2 -pS $filename runTest exiv2 -eC --force $filename mv $iccname_ big_2.icc - + test2120 copyTestFile small.icc $iccname_ runTest exiv2 -iC $filename - runTest exiv2 -pC $filename > small_.icc + runTest exiv2 -pC $filename > small_1.icc runTest exiv2 -pS $filename runTest exiv2 -eC --force $filename mv $iccname_ small_2.icc + test2120 + + for f in reagan small big; do for i in 1 2; do - md5 ${f}${i}_.icc + md5 ${f}_${i}.icc done ; done + + ) 3>&1 > $results 2>&1 printf "\n"