Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6482f53 authored by Pawan Wagh's avatar Pawan Wagh Committed by Automerger Merge Worker
Browse files

Merge "Throw exception when trying to allocate memory above 1MB limit" am:...

Merge "Throw exception when trying to allocate memory above 1MB limit" am: b7ca6017 am: cdb8f164 am: d7f67d4c am: af1919a1 am: 51e590b2 am: 636b9a15

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2578418



Change-Id: If6c06439d98ac21a5cff3d56891741411f3d3d6c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents bae1e2cd 636b9a15
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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;
@@ -1550,6 +1551,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);
    }
@@ -1561,12 +1565,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);
        }
    }