Skip to content

Commit

Permalink
Revert "Sometimes the Apple metadata is stored as a String. This fix …
Browse files Browse the repository at this point in the history
…will prevent a ClassCastException"

This reverts commit 621b1fe.
  • Loading branch information
Eunen van, M (Micha) authored and Eunen van, M (Micha) committed Sep 13, 2022
1 parent 621b1fe commit dca7468
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions Source/com/drew/metadata/apple/AppleRunTimeReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
* Reads the <tt>AppleRunTime</tt> 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();
Expand All @@ -44,10 +46,11 @@ public void extract(@NotNull byte[] bytes, @NotNull final Metadata metadata, @No
* if the <tt>flag</tt> indicates that the CMTime structure is &quot;valid&quot;.
*
* @param directory The <tt>AppleRunTimeMakernoteDirectory</tt> 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<Map.Entry<Byte, Byte>> entrySet = results.getEntrySet();
Expand All @@ -56,31 +59,21 @@ private static void processAppleRunTime(@NotNull final AppleRunTimeMakernoteDire
HashMap<String, Object> values = new HashMap<String, Object>(entrySet.size());

for (Map.Entry<Byte, Byte> 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);
}

// 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"));
}
}
}
Expand Down

0 comments on commit dca7468

Please sign in to comment.