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] 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")); } } }