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

Commit 2ed0b48a authored by Ruchi Kandoi's avatar Ruchi Kandoi Committed by Andre Eisenbach
Browse files

nfc: Make NDEF validation stricter



- Check if the MB is not set for any record apart from the first one.
- If the record is chunked, first record must contain the type

Bug: 20722275
Test: Manual; write raw NDEF messages to a tag
Change-Id: I3e73fc5163bbcd8a1f23417e98f57b665f4f1fad
Signed-off-by: default avatarRuchi Kandoi <kandoiruchi@google.com>
parent 35c71533
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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;
                }