From ee7cf5e5645fa0aa8fe934b3a4f99a5b0ee6f2f8 Mon Sep 17 00:00:00 2001 From: Jonathan Harvey-Buschel Date: Wed, 14 Aug 2024 16:29:08 -0400 Subject: [PATCH] wire: check TXID length before creating outpoint --- wire/msgtx.go | 5 +++++ wire/msgtx_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/wire/msgtx.go b/wire/msgtx.go index 1864ec6e36..e4f3051c47 100644 --- a/wire/msgtx.go +++ b/wire/msgtx.go @@ -229,6 +229,11 @@ func NewOutPointFromString(outpoint string) (*OutPoint, error) { if len(parts) != 2 { return nil, errors.New("outpoint should be of the form txid:index") } + + if len(parts[0]) != chainhash.MaxHashStringSize { + return nil, errors.New("outpoint txid should be 64 hex chars") + } + hash, err := chainhash.NewHashFromStr(parts[0]) if err != nil { return nil, err diff --git a/wire/msgtx_test.go b/wire/msgtx_test.go index e6b7bae44c..62d57098f3 100644 --- a/wire/msgtx_test.go +++ b/wire/msgtx_test.go @@ -849,6 +849,15 @@ func TestTxOutPointFromString(t *testing.T) { }, err: false, }, + { + name: "normal outpoint 2 with 31-byte txid", + input: "c7762a68ff164352bd31fd95fa875204e811c09acef40ba781787eb28e3b55:42", + result: &OutPoint{ + Hash: hashFromStr("c7762a68ff164352bd31fd95fa875204e811c09acef40ba781787eb28e3b55"), + Index: 42, + }, + err: true, + }, { name: "bad string", input: "not_outpoint_not_outpoint_not_outpoint",