summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Pawan Wagh <waghpawan@google.com> 2023-03-13 19:18:58 +0000
committer Pawan Wagh <waghpawan@google.com> 2023-05-05 21:08:23 +0000
commit7b8e729f1b2542e746bd682cfa7ab8fd6cc4575c (patch)
tree5131b1c9d48acfed83c21dabcb0cd3dde08a29b4
parent247d2b12f2e3e87779ae0e5ebfc2aebcbf6e5cc4 (diff)
Throw exception when trying to allocate memory above 1MB limit
BadParcelableException is thrown when creating arrays which use more than 1MB memory Bug: 205282403 Test: m && acloud delete --all && acloud create --local-image --local-instance && atest -c android.os.ParcelTest Change-Id: I087a2b0eec0fa3c6987ae8709c1c119577551001
-rw-r--r--core/java/android/os/Parcel.java10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java
index 8d07a861a8c2..e5ad2f86ad70 100644
--- a/core/java/android/os/Parcel.java
+++ b/core/java/android/os/Parcel.java
@@ -63,6 +63,7 @@ import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -1551,6 +1552,9 @@ public final class Parcel {
}
} catch (ArithmeticException e) {
Log.e(TAG, "ArithmeticException occurred while multiplying dimensions " + e);
+ BadParcelableException badParcelableException = new BadParcelableException("Estimated "
+ + "array length is too large. Array Dimensions:" + Arrays.toString(dimensions));
+ SneakyThrow.sneakyThrow(badParcelableException);
}
ensureWithinMemoryLimit(typeSize, totalObjects);
}
@@ -1562,12 +1566,18 @@ public final class Parcel {
} catch (ArithmeticException e) {
Log.e(TAG, "ArithmeticException occurred while multiplying values " + typeSize
+ " and " + length + " Exception: " + e);
+ BadParcelableException badParcelableException = new BadParcelableException("Estimated "
+ + "allocation size is too large. typeSize: " + typeSize + " length: " + length);
+ SneakyThrow.sneakyThrow(badParcelableException);
}
boolean isInBinderTransaction = Binder.isDirectlyHandlingTransaction();
if (isInBinderTransaction && (estimatedAllocationSize > ARRAY_ALLOCATION_LIMIT)) {
Log.e(TAG, "Trying to Allocate " + estimatedAllocationSize
+ " memory, In Binder Transaction : " + isInBinderTransaction);
+ BadParcelableException e = new BadParcelableException("Allocation of size "
+ + estimatedAllocationSize + " is above allowed limit of 1MB");
+ SneakyThrow.sneakyThrow(e);
}
}