microg/GmsCore · error · ReadException

Size read is invalid start=" + start + " end=" + end

Error message

Size read is invalid start=" + start + " end=" + end

What it means

SafeParcelReader.readObjectHeader validates the size field embedded in a SafeParcelable header: it computes end = start + size and throws a ReadException if end is negative (integer overflow) or beyond parcel.dataSize(). This guards against reading a corrupted or truncated Parcel that would otherwise cause out-of-bounds reads.

Source

Thrown at play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/SafeParcelReader.java:65

        int i = readSize(parcel, header);
        if (i != expectedSize)
            throw new ReadException("Expected size " + expectedSize + " got " + i + " (0x" + Integer.toHexString(i) + ")", parcel);
    }

    @Deprecated
    public static int readStart(Parcel parcel) {
        return readObjectHeader(parcel);
    }

    public static int readObjectHeader(Parcel parcel) {
        int header = readHeader(parcel);
        int size = readSize(parcel, header);
        int start = parcel.dataPosition();
        if (getFieldId(header) != SafeParcelable.SAFE_PARCEL_OBJECT_MAGIC)
            throw new ReadException("Expected object header. Got 0x" + Integer.toHexString(header), parcel);
        int end = start + size;
        if ((end < start) || (end > parcel.dataSize()))
            throw new ReadException("Size read is invalid start=" + start + " end=" + end, parcel);
        return end;
    }

    public static int readInt(Parcel parcel, int header) {
        readExpectedSize(parcel, header, 4);
        return parcel.readInt();
    }

    public static byte readByte(Parcel parcel, int header) {
        readExpectedSize(parcel, header, 4);
        return (byte) parcel.readInt();
    }

    public static short readShort(Parcel parcel, int header) {
        readExpectedSize(parcel, header, 4);
        return (short) parcel.readInt();
    }

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Ensure the same (or format-compatible) version of the play-services library is used on both the writing and reading sides
  2. Re-create the Parcelable from its original source data instead of re-reading a suspect Parcel
  3. Catch ReadException and fall back to defaults / re-request the data rather than crashing
  4. If you own the Parcelable, bump CREATOR versioning and validate field count before reading

Example fix

// before
int end = SafeParcelReader.readObjectHeader(parcel, header);
// after
int end;
try {
    end = SafeParcelReader.readObjectHeader(parcel, header);
} catch (SafeParcelReader.ReadException e) {
    Log.w(TAG, "Corrupt parcel header", e);
    end = -1; // bail out / use defaults
}
Defensive patterns

Strategy: try-catch

Validate before calling

// best-effort pre-check when you own the parcel
if (parcel.dataSize() <= 0) { /* reject empty parcel */ }

Try / catch

try {
    int end = SafeParcelReader.readObjectHeader(parcel, header);
} catch (SafeParcelReader.ReadException e) {
    Log.w(TAG, "Malformed SafeParcelable header", e);
    // abort parse / use defaults
}

Prevention

When it happens

Trigger: Reading a Parcel written by a different version of the same Parcelable class; a Parcel corrupted in transit across processes; truncated Parcel data (end > dataSize) or a size field causing int overflow (end < start); hand-crafted or fuzzed Parcel bytes; Bundle/IBinder round-trips that dropped data.

Common situations: App A writes a Parcelable with an older play-services version and App B (or a different process) reads it with a newer format; intent extras survived serialization/deserialization incorrectly; byte-level manipulation or memory corruption of the Bundle.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/a1a6addaf68c85b6. Report an issue: GitHub.