Skip to content

Commit

Permalink
JPEG: ReadXMPMetadata(): only stop looking for XMP marker at Start Of…
Browse files Browse the repository at this point in the history
… Scan

Some images have XMP after the quantization/Huffman table markers
  • Loading branch information
rouault committed Mar 18, 2024
1 parent 634ecf0 commit 0087b66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions autotest/gdrivers/xmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
10 changes: 6 additions & 4 deletions frmts/jpeg/jpgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(abyChunkHeader) + JFIF_MARKER_SIZE,
Expand Down

0 comments on commit 0087b66

Please sign in to comment.