Skip to content
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
3 changes: 3 additions & 0 deletions strkey/signed_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func DecodeSignedPayload(address string) (*SignedPayload, error) {
}

const signerLen = 32
if len(raw) < signerLen {
return nil, errors.Errorf("signed payload too short: %d bytes", len(raw))
}
Comment on lines +63 to +65
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length in the core and rust impls actually require an inner payload length of 1.

But that seems out of scope to fix in this pr since this Pr is just fixing the unsafe slicing causing the panic. But fyi none the less and maybe we should make the Go impl more similar to the others in a future change.

rawSigner, raw := raw[:signerLen], raw[signerLen:]
signer, err := Encode(VersionByteAccountID, rawSigner)
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions strkey/signed_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,30 @@ func TestSignedPayloadErrors(t *testing.T) {
}
}

func TestDecodeSignedPayload_RejectsShortRawPayload(t *testing.T) {
testCases := []struct {
name string
payloadLen int
}{
{"0 bytes", 0},
{"10 bytes", 10},
{"31 bytes", 31},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
shortPayload := make([]byte, tc.payloadLen)
shortAddress, err := Encode(VersionByteSignedPayload, shortPayload)
assert.NoError(t, err)

sp, err := DecodeSignedPayload(shortAddress)
assert.Nil(t, sp)
assert.Error(t, err)
assert.Contains(t, err.Error(), "signed payload too short")
})
}
}

// TestSignedPayloadSizes ensures all valid payload lengths work
func TestSignedPayloadSizes(t *testing.T) {
signer := "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"
Expand Down
Loading