Skip to content

Commit

Permalink
Check the length of an NDEF message before checking the end terminato…
Browse files Browse the repository at this point in the history
…r as it is optional and could result in an IndexOfOfRangeException
  • Loading branch information
pete-intranel committed Mar 4, 2024
1 parent 202ff2d commit 7d1511b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/devices/Card/Ndef/NdefMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public static (int Start, int Size) GetStartSizeNdef(Span<byte> toExtract)
public static byte[]? ExtractMessage(Span<byte> toExtract)
{
var (idx, size) = GetStartSizeNdef(toExtract);
// Finally check that the end terminator TLV is 0xFE
bool isRealEnd = toExtract[idx + size] == 0xFE;
// Finally check that the optional end terminator TLV is 0xFE
bool isRealEnd = (toExtract.Length == idx + size) || (toExtract[idx + size] == 0xFE);
if (!isRealEnd)
{
return new byte[0];
Expand Down

0 comments on commit 7d1511b

Please sign in to comment.