Skip to content

Commit

Permalink
Extract XMP data even when the JPEG APP1 segment preamble is non-stan…
Browse files Browse the repository at this point in the history
…dard.

Closes #102.
  • Loading branch information
drewnoakes committed Apr 18, 2015
1 parent 3f13c70 commit 1067d97
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Source/com/drew/metadata/xmp/XmpReader.java
Expand Up @@ -87,7 +87,14 @@ public void readJpegSegments(@NotNull Iterable<byte[]> segments, @NotNull Metada
// XMP in a JPEG file has an identifying preamble which is not valid XML
final int preambleLength = XMP_JPEG_PREAMBLE.length();

if (segmentBytes.length < preambleLength || !XMP_JPEG_PREAMBLE.equalsIgnoreCase(new String(segmentBytes, 0, preambleLength)))
if (segmentBytes.length < preambleLength)
continue;

// NOTE we expect the full preamble here, but some images (such as that reported on GitHub #102)
// start with "XMP\0://ns.adobe.com/xap/1.0/" which appears to be an error but is easily recovered
// from. In such cases, the actual XMP data begins at the same offset.
if (!XMP_JPEG_PREAMBLE.equalsIgnoreCase(new String(segmentBytes, 0, preambleLength)) &&
!"XMP".equalsIgnoreCase(new String(segmentBytes, 0, 3)))
continue;

byte[] xmlBytes = new byte[segmentBytes.length - preambleLength];
Expand Down

0 comments on commit 1067d97

Please sign in to comment.