Closed pete-intranel closed 3 months ago
@pete-intranel thanks a lot for the investigation and reporting the issue.
I researched a bit more, and right, the structure does not always need to finish by 0xFE. It means that your option 1 would be the best.
If you are ready for a PR, please go ahead and I'll be happy to review it!
Describe the bug
Reading NDEF message who's length is in a 16 byte boundary crashes in
NdefMessage.ExtractMessage
withIndexOutOfRangeException
This piece of code in
UltralightCard.TryReadNdefMessage(...)
will trim off the terminator TLV (0xFE) for a payload who's size is a factor ofBlockSize
MifareCard.TryReadNdefMessage(...)
appears to do something similar but slightly differently, but I haven't tried it.Then this code (in
NdefMessage.ExtractMessage
) throws the exception:I find it hard to believe I'm the only one to have seen this, so perhaps the issue lies somewhere else?
If this is a real bug, I'm not sure on the best approach to fix it.
Option 1: ExtractMessage could loosen its constraints (the specs seem to indicate that the terminator is optional anyway?), e.g.
Option 2: Include the terminator by reading an extra block:
Option 3: Both option 1 and 2