From 0087b66661e5df0f050efc71ce952861baeab7f5 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 14 Mar 2024 11:09:46 +0100 Subject: [PATCH] JPEG: ReadXMPMetadata(): only stop looking for XMP marker at Start Of Scan Some images have XMP after the quantization/Huffman table markers --- .../data/jpeg/byte_with_xmp_before_soc.jpg | Bin 0 -> 4105 bytes autotest/gdrivers/xmp.py | 1 + frmts/jpeg/jpgdataset.cpp | 10 ++++++---- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 autotest/gdrivers/data/jpeg/byte_with_xmp_before_soc.jpg diff --git a/autotest/gdrivers/data/jpeg/byte_with_xmp_before_soc.jpg b/autotest/gdrivers/data/jpeg/byte_with_xmp_before_soc.jpg new file mode 100644 index 0000000000000000000000000000000000000000..755e126dc52da8cad70467aac6c58dde34be83aa GIT binary patch literal 4105 zcmex=^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<Jq?U}9uuW@2GxWo2Ojs;&jfGq4D<3Mm>o zvIz$!vMUve7&T5@$f4}C@t|nX#SbdRNkvVZTw>x9l2WQ_>Kd9_CZ=ZQ7M51dF0O9w z9-dyoA)#U65s^{JDXD4c8JStdC8cHM6_r)ZEv;?s9i3g1CQq3GGAU*RJ2VdF$b$$4{OPfBE|D z`;VW${y*fC%qS@-u+rDhE7nU)$xlkvOU}>LuShJ=H`FuGXRxuaC`e4sPAySLN=?tq zvsHh;d%wCuW{RzPxT&v!Z-H}aMy5wqQEG6NUr2IQcCuxPy1gBjO@&oOZb5EpNuokU zZcbjYRfVlO*l;T#8zii+t^ih2l5MN*nVXoNYGvhGk(m~fpP!>(u4iGX4m6`ECCw_x z#SLl#kY}q7b!vHexn8-kUVc%!zM-Y1rM`iYzLAkGP=#)BWnM{Qg>GK4GSCDr1+W<| zsl~}fnFS@8`FRQ;GZT~YOG|9k)wvX)MyDjhO)e-c$^o03lB}PalbV~FS5gcN2t$3K zaS94HDalqT2-8495Gx#WO28ZlFDDaZuvJcCUb?M%g)T7e5=(PR)a{TQVxtdoNlqrj z2rvg~hK)X^B_Ml?OOvuvlOfiCz2%gcj$)@>gl_FoPk=kOGAG*ec0PL!<s4fw)#qnI**msYStw zxdq5R3QjFV4Ll1h4u>kT(Z_C*4OrMYKewPLwYV6Vy6g<0N|D7t$p)+toXmYv^U_N) z?2HVcDv z0O$kSgHcOJ3ggk>8VxRzLVzU2qp52&xJU{Ck`#}ouF>EkDFjGTOrO++=;o#70sD64 zz)sx%TMQhGz|OQi!>mWQ-}D4o27WO6({9`G`saTJt7Tqqg~X)i2#CMFzuu=oD||<_ zLx;M`rgp`$2|M4O_;T>^_3Ngh4?n4;-uln*=0mvMk6-<-@69^1#$a|-n&gpYX;0-= z$+wr)FE2Q1<0`zut}1=uDdzK6{xi(Gdg)czh4`2yyb`@`%p%D%jSQ!qwE1gz|Ju&( leyywRQ&|%GKbm>I;4gmvXVvBy%e(`8jdg)PdAR=H1OVyTa6te7 literal 0 HcmV?d00001 diff --git a/autotest/gdrivers/xmp.py b/autotest/gdrivers/xmp.py index f0c8238dffbd..44d16432b802 100755 --- a/autotest/gdrivers/xmp.py +++ b/autotest/gdrivers/xmp.py @@ -44,6 +44,7 @@ ["GIF", "data/gif/byte_with_xmp.gif", True], ["BIGGIF", "data/gif/fakebig.gif", False], ["JPEG", "data/jpeg/byte_with_xmp.jpg", True], + ["JPEG", "data/jpeg/byte_with_xmp_before_soc.jpg", True], ["JPEG", "data/jpeg/rgbsmall_rgb.jpg", False], ["PNG", "data/png/byte_with_xmp.png", True], ["PNG", "data/png/test.png", False], diff --git a/frmts/jpeg/jpgdataset.cpp b/frmts/jpeg/jpgdataset.cpp index 3256371402d1..d838c5487ad5 100644 --- a/frmts/jpeg/jpgdataset.cpp +++ b/frmts/jpeg/jpgdataset.cpp @@ -328,12 +328,14 @@ void JPGDatasetCommon::ReadXMPMetadata() break; nChunkLoc += 2 + abyChunkHeader[2] * 256 + abyChunkHeader[3]; - // COM marker. - if (abyChunkHeader[0] == 0xFF && abyChunkHeader[1] == 0xFE) + + // Not a marker + if (abyChunkHeader[0] != 0xFF) continue; - if (abyChunkHeader[0] != 0xFF || (abyChunkHeader[1] & 0xf0) != 0xe0) - break; // Not an APP chunk. + // Stop on Start of Scan + if (abyChunkHeader[1] == 0xDA) + break; if (abyChunkHeader[1] == APP1_BYTE && memcmp(reinterpret_cast(abyChunkHeader) + JFIF_MARKER_SIZE,