From f587113b7b623ec8fa334c9a99cdfe7866bda5a8 Mon Sep 17 00:00:00 2001 From: normana10 Date: Thu, 30 Apr 2020 10:25:51 -0400 Subject: [PATCH] ItemInfoBox no longer throws exception when no content encoding is present --- .../drew/metadata/heif/boxes/ItemInfoBox.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Source/com/drew/metadata/heif/boxes/ItemInfoBox.java b/Source/com/drew/metadata/heif/boxes/ItemInfoBox.java index 1131e5ba6..c3cd8055d 100644 --- a/Source/com/drew/metadata/heif/boxes/ItemInfoBox.java +++ b/Source/com/drew/metadata/heif/boxes/ItemInfoBox.java @@ -69,13 +69,16 @@ public ItemInfoEntry(SequentialReader reader, Box box) throws IOException { super(reader, box); + // 4 Bytes for length, 4 Bytes for type. Reader is indexed from AFTER type but box.size INCLUDES the aforementioned 8 bytes + int headerLength = 8; + if ((version == 0) || (version == 1)) { itemID = reader.getUInt16(); itemProtectionIndex = reader.getUInt16(); - itemName = reader.getNullTerminatedString((int)(box.size - reader.getPosition()), Charsets.UTF_8); - contentType = reader.getNullTerminatedString((int)(box.size - reader.getPosition()), Charsets.UTF_8); - if (box.size - reader.getPosition() > 0) { - extensionType = reader.getNullTerminatedString((int) (box.size - reader.getPosition()), Charsets.UTF_8); + itemName = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); + contentType = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); + if (box.size - reader.getPosition() - headerLength > 0) { + extensionType = reader.getNullTerminatedString((int) (box.size - reader.getPosition() - headerLength), Charsets.UTF_8); } } if (version == 1) { @@ -92,14 +95,14 @@ public ItemInfoEntry(SequentialReader reader, Box box) throws IOException itemProtectionIndex = reader.getUInt16(); itemType = reader.getString(4); - itemName = reader.getNullTerminatedString((int)(box.size - reader.getPosition()), Charsets.UTF_8); + itemName = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); if (itemType.equals("mime")) { - contentType = reader.getNullTerminatedString((int)(box.size - reader.getPosition()), Charsets.UTF_8); - if (box.size - reader.getPosition() > 0) { - contentEncoding = reader.getNullTerminatedString((int)(box.size - reader.getPosition()), Charsets.UTF_8); + contentType = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); + if (box.size - reader.getPosition() - headerLength > 0) { + contentEncoding = reader.getNullTerminatedString((int)(box.size - reader.getPosition() - headerLength), Charsets.UTF_8); } } else if (itemType.equals("uri ")) { - itemUriType = reader.getString((int)(box.size - reader.getPosition())); + itemUriType = reader.getString((int)(box.size - reader.getPosition() - headerLength)); } } }