Skip to content

Commit 675ab95

Browse files
committed
Pass start offset when reading Exif
1 parent 3a975db commit 675ab95

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

Source/com/drew/metadata/exif/ExifReader.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void readJpegSegments(@NotNull final Iterable<byte[]> segments, @NotNull
6363
for (byte[] segmentBytes : segments) {
6464
// Segment must have the expected preamble
6565
if (startsWithJpegExifPreamble(segmentBytes)) {
66-
extract(new ByteArrayReader(segmentBytes, JPEG_SEGMENT_PREAMBLE.length()), metadata);
66+
extract(new ByteArrayReader(segmentBytes, JPEG_SEGMENT_PREAMBLE.length()), metadata, JPEG_SEGMENT_PREAMBLE.length());
6767
}
6868
}
6969
}
@@ -76,15 +76,15 @@ public static boolean startsWithJpegExifPreamble(byte[] bytes)
7676
}
7777

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

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

8989
try {
9090
// Read the TIFF-formatted Exif data

Source/com/drew/metadata/heif/HeifPictureHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private void handleItem(@NotNull ItemInfoBox.ItemInfoEntry entry,
151151
}
152152
payloadReader.skip(tiffHeaderOffset);
153153
ByteArrayInputStream tiffStream = new ByteArrayInputStream(payloadReader.getBytes(payloadReader.available()));
154-
new ExifReader().extract(new RandomAccessStreamReader(tiffStream), metadata);
154+
new ExifReader().extract(new RandomAccessStreamReader(tiffStream), metadata, 0);
155155
}
156156
}
157157

Source/com/drew/metadata/mp4/media/Mp4UuidBoxHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public Mp4Handler<?> processBox(@NotNull String type, byte[] payload, long boxSi
114114

115115
switch (uuidType) {
116116
case Exif:
117-
new ExifReader().extract(new ByteArrayReader(payload, 16), metadata, directory);
117+
new ExifReader().extract(new ByteArrayReader(payload, 16), metadata, directory, 0);
118118
break;
119119
case IptcIim:
120120
new IptcReader().extract(new SequentialByteArrayReader(payload, 16), metadata, payload.length - 16, directory);

Source/com/drew/metadata/photoshop/PhotoshopReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void extract(@NotNull final SequentialReader reader, int length, @NotNull
151151
else if (tagType == PhotoshopDirectory.TAG_ICC_PROFILE_BYTES)
152152
new IccReader().extract(new ByteArrayReader(tagBytes), metadata, directory);
153153
else if (tagType == PhotoshopDirectory.TAG_EXIF_DATA_1 || tagType == PhotoshopDirectory.TAG_EXIF_DATA_3)
154-
new ExifReader().extract(new ByteArrayReader(tagBytes), metadata, directory);
154+
new ExifReader().extract(new ByteArrayReader(tagBytes), metadata, directory, 0);
155155
else if (tagType == PhotoshopDirectory.TAG_XMP_DATA)
156156
new XmpReader().extract(tagBytes, metadata, directory);
157157
else if (tagType >= 0x07D0 && tagType <= 0x0BB6) {

Source/com/drew/metadata/webp/WebpRiffHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void processChunk(@NotNull String fourCC, @NotNull byte[] payload)
8383
ByteArrayReader reader = ExifReader.startsWithJpegExifPreamble(payload)
8484
? new ByteArrayReader(payload, ExifReader.JPEG_SEGMENT_PREAMBLE.length())
8585
: new ByteArrayReader(payload);
86-
new ExifReader().extract(reader, _metadata);
86+
new ExifReader().extract(reader, _metadata, 0);
8787
} else if (fourCC.equals(WebpDirectory.CHUNK_ICCP)) {
8888
new IccReader().extract(new ByteArrayReader(payload), _metadata);
8989
} else if (fourCC.equals(WebpDirectory.CHUNK_XMP)) {

Tests/com/drew/metadata/exif/ExifReaderTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static Metadata processBytes(@NotNull String filePath) throws IOException
4646
{
4747
Metadata metadata = new Metadata();
4848
byte[] bytes = FileUtil.readBytes(filePath);
49-
new ExifReader().extract(new ByteArrayReader(bytes, ExifReader.JPEG_SEGMENT_PREAMBLE.length()), metadata, null);
49+
new ExifReader().extract(new ByteArrayReader(bytes, ExifReader.JPEG_SEGMENT_PREAMBLE.length()), metadata, null, ExifReader.JPEG_SEGMENT_PREAMBLE.length());
5050
return metadata;
5151
}
5252

0 commit comments

Comments
 (0)