From 473201868c0cb6d6fef4550c7aeb9c1ba7432d98 Mon Sep 17 00:00:00 2001 From: Jin Seok Park Date: Tue, 20 Mar 2018 10:23:46 +0900 Subject: [PATCH] ExifInterface: Remove casting int[] to long[] This CL removes code that directly casts int[] to long[] and instead iterates through the individual values and casts to int if necessary. They are cast to integer because StripOffsets/StripByteCounts Attributes can return either int[] or long[] values, but the maximum length of a file that ExifInterface can handle is the maximum value of integer, so it should be safe to cast the long values to integer values. Bug: 73091048 Test: Cts Change-Id: I9f3b98204e0829a8a8a30927bb8c0a698c457654 --- media/java/android/media/ExifInterface.java | 31 +++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java index 91754162180fc..bc0e43b5e9c67 100644 --- a/media/java/android/media/ExifInterface.java +++ b/media/java/android/media/ExifInterface.java @@ -3226,9 +3226,18 @@ public class ExifInterface { if (stripOffsetsAttribute != null && stripByteCountsAttribute != null) { long[] stripOffsets = - (long[]) stripOffsetsAttribute.getValue(mExifByteOrder); + convertToLongArray(stripOffsetsAttribute.getValue(mExifByteOrder)); long[] stripByteCounts = - (long[]) stripByteCountsAttribute.getValue(mExifByteOrder); + convertToLongArray(stripByteCountsAttribute.getValue(mExifByteOrder)); + + if (stripOffsets == null) { + Log.w(TAG, "stripOffsets should not be null."); + return; + } + if (stripByteCounts == null) { + Log.w(TAG, "stripByteCounts should not be null."); + return; + } // Set thumbnail byte array data for non-consecutive strip bytes byte[] totalStripBytes = @@ -4025,4 +4034,22 @@ public class ExifInterface { } return false; } + + /** + * Convert given int[] to long[]. If long[] is given, just return it. + * Return null for other types of input. + */ + private static long[] convertToLongArray(Object inputObj) { + if (inputObj instanceof int[]) { + int[] input = (int[]) inputObj; + long[] result = new long[input.length]; + for (int i = 0; i < input.length; i++) { + result[i] = input[i]; + } + return result; + } else if (inputObj instanceof long[]) { + return (long[]) inputObj; + } + return null; + } }