@@ -73,10 +73,15 @@ constexpr Internal::TagDetails jpegProcessMarkerTags[] = {
7373 {sof15_, N_ (" Lossless, differential arithmetic coding" )},
7474};
7575
76- constexpr auto exifId_ = " Exif\0\0 " ; // !< Exif identifier
77- // constexpr auto jfifId_ = "JFIF\0"; //!< JFIF identifier
78- constexpr auto xmpId_ = " http://ns.adobe.com/xap/1.0/\0 " ; // !< XMP packet identifier
79- constexpr auto iccId_ = " ICC_PROFILE\0 " ; // !< ICC profile identifier
76+ constexpr std::array<byte, 6 > exifId_{
77+ ' E' , ' x' , ' i' , ' f' , ' \0 ' , ' \0 ' ,
78+ }; // !< Exif identifier
79+ constexpr std::array<byte, 29 > xmpId_{
80+ ' h' , ' t' , ' t' , ' p' , ' :' , ' /' , ' /' , ' n' , ' s' , ' .' , ' a' , ' d' , ' o' , ' b' , ' e' ,
81+ ' .' , ' c' , ' o' , ' m' , ' /' , ' x' , ' a' , ' p' , ' /' , ' 1' , ' .' , ' 0' , ' /' , 0x0 ,
82+ }; // !< XMP packet identifier
83+ // constexpr auto jfifId_ = "JFIF"; //!< JFIF identifier
84+ constexpr auto iccId_ = " ICC_PROFILE" ; // !< ICC profile identifier
8085
8186constexpr bool inRange (int lo, int value, int hi) {
8287 return lo <= value && value <= hi;
@@ -183,7 +188,7 @@ void JpegBase::readMetadata() {
183188 }
184189
185190 if (!foundExifData && marker == app1_ && size >= 8 // prevent out-of-bounds read in memcmp on next line
186- && buf.cmpBytes (2 , exifId_, 6 ) == 0 ) {
191+ && buf.cmpBytes (2 , exifId_. data () , 6 ) == 0 ) {
187192 ByteOrder bo = ExifParser::decode (exifData_, buf.c_data (8 ), size - 8 );
188193 setByteOrder (bo);
189194 if (size > 8 && byteOrder () == invalidByteOrder) {
@@ -195,7 +200,7 @@ void JpegBase::readMetadata() {
195200 --search;
196201 foundExifData = true ;
197202 } else if (!foundXmpData && marker == app1_ && size >= 31 // prevent out-of-bounds read in memcmp on next line
198- && buf.cmpBytes (2 , xmpId_, 29 ) == 0 ) {
203+ && buf.cmpBytes (2 , xmpId_. data () , 29 ) == 0 ) {
199204 xmpPacket_.assign (buf.c_str (31 ), size - 31 );
200205 if (!xmpPacket_.empty () && XmpParser::decode (xmpData_, xmpPacket_)) {
201206#ifndef SUPPRESS_WARNINGS
@@ -646,7 +651,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
646651 insertPos = count + 1 ;
647652 } else if (skipApp1Exif == notfound && marker == app1_ &&
648653 buf.size () >= 8 && // prevent out-of-bounds read in memcmp on next line
649- buf.cmpBytes (2 , exifId_, 6 ) == 0 ) {
654+ buf.cmpBytes (2 , exifId_. data () , 6 ) == 0 ) {
650655 skipApp1Exif = count;
651656 ++search;
652657 if (buf.size () > 8 ) {
@@ -655,7 +660,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
655660 }
656661 } else if (skipApp1Xmp == notfound && marker == app1_ &&
657662 buf.size () >= 31 && // prevent out-of-bounds read in memcmp on next line
658- buf.cmpBytes (2 , xmpId_, 29 ) == 0 ) {
663+ buf.cmpBytes (2 , xmpId_. data () , 29 ) == 0 ) {
659664 skipApp1Xmp = count;
660665 ++search;
661666 } else if (marker == app2_ && buf.size () >= 13 && // prevent out-of-bounds read in memcmp on next line
@@ -756,7 +761,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
756761 if (exifSize > 0xffff - 8 )
757762 throw Error (ErrorCode::kerTooLargeJpegSegment, " Exif" );
758763 us2Data (tmpBuf.data () + 2 , static_cast <uint16_t >(exifSize + 8 ), bigEndian);
759- std::copy_n (exifId_, 6 , tmpBuf.begin () + 4 );
764+ std::copy (exifId_. begin (), exifId_. end () , tmpBuf.begin () + 4 );
760765 if (outIo.write (tmpBuf.data (), 10 ) != 10 )
761766 throw Error (ErrorCode::kerImageWriteFailed);
762767
@@ -783,7 +788,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
783788 if (xmpPacket_.size () > 0xffff - 31 )
784789 throw Error (ErrorCode::kerTooLargeJpegSegment, " XMP" );
785790 us2Data (tmpBuf.data () + 2 , static_cast <uint16_t >(xmpPacket_.size () + 31 ), bigEndian);
786- std::copy_n (xmpId_, 29 , tmpBuf.begin () + 4 );
791+ std::copy (xmpId_. begin (), xmpId_. end () , tmpBuf.begin () + 4 );
787792 if (outIo.write (tmpBuf.data (), 33 ) != 33 )
788793 throw Error (ErrorCode::kerImageWriteFailed);
789794
0 commit comments