Skip to content

Commit

Permalink
Pass start offset when reading Exif
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Jul 24, 2024
1 parent 3a975db commit 675ab95
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Source/com/drew/metadata/exif/ExifReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void readJpegSegments(@NotNull final Iterable<byte[]> segments, @NotNull
for (byte[] segmentBytes : segments) {
// Segment must have the expected preamble
if (startsWithJpegExifPreamble(segmentBytes)) {
extract(new ByteArrayReader(segmentBytes, JPEG_SEGMENT_PREAMBLE.length()), metadata);
extract(new ByteArrayReader(segmentBytes, JPEG_SEGMENT_PREAMBLE.length()), metadata, JPEG_SEGMENT_PREAMBLE.length());
}
}
}
Expand All @@ -76,15 +76,15 @@ public static boolean startsWithJpegExifPreamble(byte[] bytes)
}

/** Reads TIFF formatted Exif data a specified offset within a {@link RandomAccessReader}. */
public void extract(@NotNull final RandomAccessReader reader, @NotNull final Metadata metadata)
public void extract(@NotNull final RandomAccessReader reader, @NotNull final Metadata metadata, int preambleLength)
{
extract(reader, metadata, null);
extract(reader, metadata, null, preambleLength);
}

/** Reads TIFF formatted Exif data at a specified offset within a {@link RandomAccessReader}. */
public void extract(@NotNull final RandomAccessReader reader, @NotNull final Metadata metadata, @Nullable Directory parentDirectory)
public void extract(@NotNull final RandomAccessReader reader, @NotNull final Metadata metadata, @Nullable Directory parentDirectory, int exifStartOffset)
{
ExifTiffHandler exifTiffHandler = new ExifTiffHandler(metadata, parentDirectory, /*readerOffset*/ 0); // FIXME what to do?
ExifTiffHandler exifTiffHandler = new ExifTiffHandler(metadata, parentDirectory, exifStartOffset);

try {
// Read the TIFF-formatted Exif data
Expand Down
2 changes: 1 addition & 1 deletion Source/com/drew/metadata/heif/HeifPictureHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void handleItem(@NotNull ItemInfoBox.ItemInfoEntry entry,
}
payloadReader.skip(tiffHeaderOffset);
ByteArrayInputStream tiffStream = new ByteArrayInputStream(payloadReader.getBytes(payloadReader.available()));
new ExifReader().extract(new RandomAccessStreamReader(tiffStream), metadata);
new ExifReader().extract(new RandomAccessStreamReader(tiffStream), metadata, 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/com/drew/metadata/mp4/media/Mp4UuidBoxHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Mp4Handler<?> processBox(@NotNull String type, byte[] payload, long boxSi

switch (uuidType) {
case Exif:
new ExifReader().extract(new ByteArrayReader(payload, 16), metadata, directory);
new ExifReader().extract(new ByteArrayReader(payload, 16), metadata, directory, 0);
break;
case IptcIim:
new IptcReader().extract(new SequentialByteArrayReader(payload, 16), metadata, payload.length - 16, directory);
Expand Down
2 changes: 1 addition & 1 deletion Source/com/drew/metadata/photoshop/PhotoshopReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void extract(@NotNull final SequentialReader reader, int length, @NotNull
else if (tagType == PhotoshopDirectory.TAG_ICC_PROFILE_BYTES)
new IccReader().extract(new ByteArrayReader(tagBytes), metadata, directory);
else if (tagType == PhotoshopDirectory.TAG_EXIF_DATA_1 || tagType == PhotoshopDirectory.TAG_EXIF_DATA_3)
new ExifReader().extract(new ByteArrayReader(tagBytes), metadata, directory);
new ExifReader().extract(new ByteArrayReader(tagBytes), metadata, directory, 0);
else if (tagType == PhotoshopDirectory.TAG_XMP_DATA)
new XmpReader().extract(tagBytes, metadata, directory);
else if (tagType >= 0x07D0 && tagType <= 0x0BB6) {
Expand Down
2 changes: 1 addition & 1 deletion Source/com/drew/metadata/webp/WebpRiffHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void processChunk(@NotNull String fourCC, @NotNull byte[] payload)
ByteArrayReader reader = ExifReader.startsWithJpegExifPreamble(payload)
? new ByteArrayReader(payload, ExifReader.JPEG_SEGMENT_PREAMBLE.length())
: new ByteArrayReader(payload);
new ExifReader().extract(reader, _metadata);
new ExifReader().extract(reader, _metadata, 0);
} else if (fourCC.equals(WebpDirectory.CHUNK_ICCP)) {
new IccReader().extract(new ByteArrayReader(payload), _metadata);
} else if (fourCC.equals(WebpDirectory.CHUNK_XMP)) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/com/drew/metadata/exif/ExifReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static Metadata processBytes(@NotNull String filePath) throws IOException
{
Metadata metadata = new Metadata();
byte[] bytes = FileUtil.readBytes(filePath);
new ExifReader().extract(new ByteArrayReader(bytes, ExifReader.JPEG_SEGMENT_PREAMBLE.length()), metadata, null);
new ExifReader().extract(new ByteArrayReader(bytes, ExifReader.JPEG_SEGMENT_PREAMBLE.length()), metadata, null, ExifReader.JPEG_SEGMENT_PREAMBLE.length());
return metadata;
}

Expand Down

0 comments on commit 675ab95

Please sign in to comment.