Skip to content

Commit

Permalink
fix ndef bounds checking
Browse files Browse the repository at this point in the history
  • Loading branch information
wizzomafizzo committed May 21, 2024
1 parent dc026b3 commit f263740
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/tokens/ndef.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@ func ParseRecordText(blocks []byte) (string, error) {
return "", fmt.Errorf("NDEF end not found: %x", blocks)
}

startIndex += 4
if startIndex >= endIndex || startIndex+4 >= len(blocks) {
return "", fmt.Errorf("start index out of bounds: %d, %x", startIndex, blocks)
}

if endIndex <= startIndex || endIndex+1 >= len(blocks) {
if endIndex <= startIndex || endIndex >= len(blocks) {
return "", fmt.Errorf("end index out of bounds: %d, %x", endIndex, blocks)
}

tagText := string(blocks[startIndex:endIndex])
tagText := string(blocks[startIndex+4 : endIndex])

return tagText, nil
}
Expand Down

0 comments on commit f263740

Please sign in to comment.