Skip to content

Commit

Permalink
Merge pull request #470 from normana10/master
Browse files Browse the repository at this point in the history
ItemInfoBox no longer throws exception when no content encoding is present
  • Loading branch information
drewnoakes authored May 5, 2020
2 parents f65e53a + f587113 commit 64b7176
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Source/com/drew/metadata/heif/boxes/ItemInfoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
}
}
}
Expand Down

0 comments on commit 64b7176

Please sign in to comment.