diff --git a/core/java/android/nfc/NdefRecord.java b/core/java/android/nfc/NdefRecord.java index 83d17ba7fdd29..bd3231464ccf1 100644 --- a/core/java/android/nfc/NdefRecord.java +++ b/core/java/android/nfc/NdefRecord.java @@ -805,7 +805,7 @@ public final class NdefRecord implements Parcelable { if (!mb && records.size() == 0 && !inChunk && !ignoreMbMe) { throw new FormatException("expected MB flag"); - } else if (mb && records.size() != 0 && !ignoreMbMe) { + } else if (mb && (records.size() != 0 || inChunk) && !ignoreMbMe) { throw new FormatException("unexpected MB flag"); } else if (inChunk && il) { throw new FormatException("unexpected IL flag in non-leading chunk"); @@ -839,6 +839,9 @@ public final class NdefRecord implements Parcelable { if (cf && !inChunk) { // first chunk + if (typeLength == 0) { + throw new FormatException("expected non-zero type length in first chunk"); + } chunks.clear(); chunkTnf = tnf; }