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

Commit 3adcf170 authored by Steven Moreland's avatar Steven Moreland
Browse files

BaseBundle: fix unparcel error logic

This code considered a success case to be an unsuccessful
case.

Bug: 373357090
Test: repro in bug no longer works
Merged-In: Id423936872cbb0e0265ccf2855092357cb175d47
Change-Id: Id423936872cbb0e0265ccf2855092357cb175d47
parent 43b48fcb
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -437,12 +437,15 @@ public class BaseBundle {
            map.erase();
            map.ensureCapacity(count);
        }

        int[] numLazyValues = new int[]{0};

        try {
            // recycleParcel being false implies that we do not own the parcel. In this case, do
            // not use lazy values to be safe, as the parcel could be recycled outside of our
            // control.
            recycleParcel &= parcelledData.readArrayMap(map, count, !parcelledByNative,
                    /* lazy */ recycleParcel, mClassLoader);
            parcelledData.readArrayMap(map, count, !parcelledByNative,
                    /* lazy */ recycleParcel, mClassLoader, numLazyValues);
        } catch (BadParcelableException e) {
            if (sShouldDefuse) {
                Log.w(TAG, "Failed to parse Bundle, but defusing quietly", e);
@@ -451,6 +454,8 @@ public class BaseBundle {
                throw e;
            }
        } finally {
            recycleParcel &= (numLazyValues[0] == 0);

            mMap = map;
            if (recycleParcel) {
                recycleParcel(parcelledData);
+5 −7
Original line number Diff line number Diff line
@@ -5265,7 +5265,7 @@ public final class Parcel {

    private void readArrayMapInternal(@NonNull ArrayMap<? super String, Object> outVal,
            int size, @Nullable ClassLoader loader) {
        readArrayMap(outVal, size, /* sorted */ true, /* lazy */ false, loader);
        readArrayMap(outVal, size, /* sorted */ true, /* lazy */ false, loader, null);
    }

    /**
@@ -5275,17 +5275,16 @@ public final class Parcel {
     * @param lazy   Whether to populate the map with lazy {@link Supplier} objects for
     *               length-prefixed values. See {@link Parcel#readLazyValue(ClassLoader)} for more
     *               details.
     * @return whether the parcel can be recycled or not.
     * @param lazyValueCount number of lazy values added here
     * @hide
     */
    boolean readArrayMap(ArrayMap<? super String, Object> map, int size, boolean sorted,
            boolean lazy, @Nullable ClassLoader loader) {
        boolean recycle = true;
    void readArrayMap(ArrayMap<? super String, Object> map, int size, boolean sorted,
            boolean lazy, @Nullable ClassLoader loader, int[] lazyValueCount) {
        while (size > 0) {
            String key = readString();
            Object value = (lazy) ? readLazyValue(loader) : readValue(loader);
            if (value instanceof LazyValue) {
                recycle = false;
                lazyValueCount[0]++;
            }
            if (sorted) {
                map.append(key, value);
@@ -5297,7 +5296,6 @@ public final class Parcel {
        if (sorted) {
            map.validate();
        }
        return recycle;
    }

    /**