From 621b1fef452c7c2022cd6d04a7d4e6a175bd798e Mon Sep 17 00:00:00 2001 From: "Eunen van, M (Micha)" Date: Tue, 13 Sep 2022 11:40:59 +0200 Subject: [PATCH 1/3] Sometimes the Apple metadata is stored as a String. This fix will prevent a ClassCastException --- .../metadata/apple/AppleRunTimeReader.java | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/Source/com/drew/metadata/apple/AppleRunTimeReader.java b/Source/com/drew/metadata/apple/AppleRunTimeReader.java index 279b08053..483b4d9be 100644 --- a/Source/com/drew/metadata/apple/AppleRunTimeReader.java +++ b/Source/com/drew/metadata/apple/AppleRunTimeReader.java @@ -16,15 +16,13 @@ * Reads the AppleRunTime data and adds {@link AppleRunTimeMakernoteDirectory} to the * parent {@link AppleMakernoteDirectory} if it can be parsed with no errors. */ -public class AppleRunTimeReader -{ - public void extract(@NotNull byte[] bytes, @NotNull final Metadata metadata, @NotNull final Directory parentDirectory) - { +public class AppleRunTimeReader { + public void extract(@NotNull byte[] bytes, @NotNull final Metadata metadata, @NotNull final Directory parentDirectory) { parentDirectory.setByteArray(AppleMakernoteDirectory.TAG_RUN_TIME, bytes); if (!BplistReader.isValid(bytes)) { - parentDirectory.addError("Input array is not a bplist"); - return; + parentDirectory.addError("Input array is not a bplist"); + return; } AppleRunTimeMakernoteDirectory directory = new AppleRunTimeMakernoteDirectory(); @@ -46,11 +44,10 @@ public void extract(@NotNull byte[] bytes, @NotNull final Metadata metadata, @No * if the flag indicates that the CMTime structure is "valid". * * @param directory The AppleRunTimeMakernoteDirectory to set values onto. - * @param bplist The BPLIST + * @param bplist The BPLIST * @throws IOException Thrown if an error occurs parsing the BPLIST as a CMTime structure. */ - private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDirectory directory, @NotNull final byte[] bplist) throws IOException - { + private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDirectory directory, @NotNull final byte[] bplist) throws IOException { final BplistReader.PropertyListResults results = BplistReader.parse(bplist); final Set> entrySet = results.getEntrySet(); @@ -59,7 +56,7 @@ private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDire HashMap values = new HashMap(entrySet.size()); for (Map.Entry entry : entrySet) { - String key = (String)results.getObjects().get(entry.getKey()); + String key = (String) results.getObjects().get(entry.getKey()); Object value = results.getObjects().get(entry.getValue()); values.put(key, value); @@ -67,13 +64,23 @@ private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDire // https://developer.apple.com/documentation/coremedia/cmtime-u58 - byte flags = (Byte)values.get("flags"); - - if ((flags & 0x1) == 0x1) { - directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeFlags, flags); - directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeEpoch, (Byte)values.get("epoch")); - directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeScale, (Long)values.get("timescale")); - directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeValue, (Long)values.get("value")); + Object flagsObject = values.get("flags"); + if (flagsObject instanceof Byte) { + byte flags = (Byte) flagsObject; + if ((flags & 0x1) == 0x1) { + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeFlags, flags); + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeEpoch, (Byte) values.get("epoch")); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeScale, (Long) values.get("timescale")); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeValue, (Long) values.get("value")); + } + } else if (flagsObject instanceof String) { + byte flags = Byte.parseByte((String) flagsObject); + if ((flags & 0x1) == 0x1) { + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeFlags, flags); + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeEpoch, Byte.parseByte((String) values.get("epoch"))); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeScale, Long.parseLong((String) values.get("timescale"))); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeValue, Long.parseLong((String) values.get("value"))); + } } } } From dca7468714817a38486d6b3cc8635926d56ab104 Mon Sep 17 00:00:00 2001 From: "Eunen van, M (Micha)" Date: Tue, 13 Sep 2022 13:19:57 +0200 Subject: [PATCH 2/3] Revert "Sometimes the Apple metadata is stored as a String. This fix will prevent a ClassCastException" This reverts commit 621b1fef452c7c2022cd6d04a7d4e6a175bd798e. --- .../metadata/apple/AppleRunTimeReader.java | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/Source/com/drew/metadata/apple/AppleRunTimeReader.java b/Source/com/drew/metadata/apple/AppleRunTimeReader.java index 483b4d9be..279b08053 100644 --- a/Source/com/drew/metadata/apple/AppleRunTimeReader.java +++ b/Source/com/drew/metadata/apple/AppleRunTimeReader.java @@ -16,13 +16,15 @@ * Reads the AppleRunTime data and adds {@link AppleRunTimeMakernoteDirectory} to the * parent {@link AppleMakernoteDirectory} if it can be parsed with no errors. */ -public class AppleRunTimeReader { - public void extract(@NotNull byte[] bytes, @NotNull final Metadata metadata, @NotNull final Directory parentDirectory) { +public class AppleRunTimeReader +{ + public void extract(@NotNull byte[] bytes, @NotNull final Metadata metadata, @NotNull final Directory parentDirectory) + { parentDirectory.setByteArray(AppleMakernoteDirectory.TAG_RUN_TIME, bytes); if (!BplistReader.isValid(bytes)) { - parentDirectory.addError("Input array is not a bplist"); - return; + parentDirectory.addError("Input array is not a bplist"); + return; } AppleRunTimeMakernoteDirectory directory = new AppleRunTimeMakernoteDirectory(); @@ -44,10 +46,11 @@ public void extract(@NotNull byte[] bytes, @NotNull final Metadata metadata, @No * if the flag indicates that the CMTime structure is "valid". * * @param directory The AppleRunTimeMakernoteDirectory to set values onto. - * @param bplist The BPLIST + * @param bplist The BPLIST * @throws IOException Thrown if an error occurs parsing the BPLIST as a CMTime structure. */ - private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDirectory directory, @NotNull final byte[] bplist) throws IOException { + private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDirectory directory, @NotNull final byte[] bplist) throws IOException + { final BplistReader.PropertyListResults results = BplistReader.parse(bplist); final Set> entrySet = results.getEntrySet(); @@ -56,7 +59,7 @@ private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDire HashMap values = new HashMap(entrySet.size()); for (Map.Entry entry : entrySet) { - String key = (String) results.getObjects().get(entry.getKey()); + String key = (String)results.getObjects().get(entry.getKey()); Object value = results.getObjects().get(entry.getValue()); values.put(key, value); @@ -64,23 +67,13 @@ private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDire // https://developer.apple.com/documentation/coremedia/cmtime-u58 - Object flagsObject = values.get("flags"); - if (flagsObject instanceof Byte) { - byte flags = (Byte) flagsObject; - if ((flags & 0x1) == 0x1) { - directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeFlags, flags); - directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeEpoch, (Byte) values.get("epoch")); - directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeScale, (Long) values.get("timescale")); - directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeValue, (Long) values.get("value")); - } - } else if (flagsObject instanceof String) { - byte flags = Byte.parseByte((String) flagsObject); - if ((flags & 0x1) == 0x1) { - directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeFlags, flags); - directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeEpoch, Byte.parseByte((String) values.get("epoch"))); - directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeScale, Long.parseLong((String) values.get("timescale"))); - directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeValue, Long.parseLong((String) values.get("value"))); - } + byte flags = (Byte)values.get("flags"); + + if ((flags & 0x1) == 0x1) { + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeFlags, flags); + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeEpoch, (Byte)values.get("epoch")); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeScale, (Long)values.get("timescale")); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeValue, (Long)values.get("value")); } } } From 0b2d61bbe58498994d24f074428df4c50beba658 Mon Sep 17 00:00:00 2001 From: "Eunen van, M (Micha)" Date: Tue, 13 Sep 2022 13:20:32 +0200 Subject: [PATCH 3/3] Sometimes the Apple metadata is stored as a String. This fix will prevent a ClassCastException --- .../metadata/apple/AppleRunTimeReader.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Source/com/drew/metadata/apple/AppleRunTimeReader.java b/Source/com/drew/metadata/apple/AppleRunTimeReader.java index 279b08053..97811f14b 100644 --- a/Source/com/drew/metadata/apple/AppleRunTimeReader.java +++ b/Source/com/drew/metadata/apple/AppleRunTimeReader.java @@ -67,13 +67,23 @@ private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDire // https://developer.apple.com/documentation/coremedia/cmtime-u58 - byte flags = (Byte)values.get("flags"); - - if ((flags & 0x1) == 0x1) { - directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeFlags, flags); - directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeEpoch, (Byte)values.get("epoch")); - directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeScale, (Long)values.get("timescale")); - directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeValue, (Long)values.get("value")); + Object flagsObject = values.get("flags"); + if (flagsObject instanceof Byte) { + byte flags = (Byte) flagsObject; + if ((flags & 0x1) == 0x1) { + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeFlags, flags); + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeEpoch, (Byte) values.get("epoch")); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeScale, (Long) values.get("timescale")); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeValue, (Long) values.get("value")); + } + } else if (flagsObject instanceof String) { + byte flags = Byte.parseByte((String) flagsObject); + if ((flags & 0x1) == 0x1) { + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeFlags, flags); + directory.setInt(AppleRunTimeMakernoteDirectory.CMTimeEpoch, Byte.parseByte((String) values.get("epoch"))); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeScale, Long.parseLong((String) values.get("timescale"))); + directory.setLong(AppleRunTimeMakernoteDirectory.CMTimeValue, Long.parseLong((String) values.get("value"))); + } } } }