Skip to content

Commit 2b1a89f

Browse files
committed
zpay32: validate UTF-8 parsing field description
1 parent 37523b6 commit 2b1a89f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

zpay32/decode.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"strings"
99
"time"
10+
"unicode/utf8"
1011

1112
"github.com/btcsuite/btcd/btcec/v2"
1213
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
@@ -18,6 +19,12 @@ import (
1819
"github.com/lightningnetwork/lnd/lnwire"
1920
)
2021

22+
var (
23+
// ErrInvalidUTF8Description is returned if the invoice description is
24+
// not valid UTF-8.
25+
ErrInvalidUTF8Description = errors.New("description is not valid UTF-8")
26+
)
27+
2128
// DecodeOption is a type that can be used to supply functional options to the
2229
// Decode function.
2330
type DecodeOption func(*decodeOptions)
@@ -446,6 +453,10 @@ func parseDescription(data []byte) (*string, error) {
446453
return nil, err
447454
}
448455

456+
if !utf8.Valid(base256Data) {
457+
return nil, ErrInvalidUTF8Description
458+
}
459+
449460
description := string(base256Data)
450461

451462
return &description, nil

0 commit comments

Comments
 (0)