Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wire: check TXID length before creating outpoint #2233

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions wire/msgtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions wire/msgtx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading