nip19: TLV infinite loop again.

probably fixes https://github.com/nbd-wtf/nostr-tools/issues/223
This commit is contained in:
fiatjaf
2026-06-15 18:22:48 -03:00
parent e17366cd2e
commit 3575368176
2 changed files with 5 additions and 0 deletions

View File

@@ -137,6 +137,10 @@ test('decode naddr from habla.news', () => {
expect(pointer.identifier).toEqual('references')
})
test('decode malformed nevent should throw instead of infinite loop', () => {
expect(() => decode('nevent1qq5v4rkz')).toThrow()
})
test('decode naddr from go-nostr with different TLV ordering', () => {
let { type, data } = decode(
'naddr1qqrxyctwv9hxzq3q80cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsxpqqqp65wqfwwaehxw309aex2mrp0yhxummnw3ezuetcv9khqmr99ekhjer0d4skjm3wv4uxzmtsd3jjucm0d5q3vamnwvaz7tmwdaehgu3wvfskuctwvyhxxmmd0zfmwx',

View File

@@ -182,6 +182,7 @@ function parseTLV(data: Uint8Array): TLV {
let result: TLV = {}
let rest = data
while (rest.length > 0) {
if (rest.length < 2) throw new Error('not enough data to read TLV')
let t = rest[0]
let l = rest[1]
let v = rest.slice(2, 2 + l)