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

unmarshalHex() panics if the public key submitted to UnmarshalText() has more than 64 hex digits #160

Closed
mike76-dev opened this issue May 19, 2024 · 1 comment · Fixed by #161

Comments

@mike76-dev
Copy link
Contributor

mike76-dev commented May 19, 2024

The panic happens in hex.Decode if the submitted public key cannot fit in 32 bytes.
Should return an error instead.

func unmarshalHex(dst []byte, prefix string, data []byte) error {
	n, err := hex.Decode(dst, bytes.TrimPrefix(data, []byte(prefix+":")))
	if n < len(dst) {
		err = io.ErrUnexpectedEOF
	}
	if err != nil {
		return fmt.Errorf("decoding %v:<hex> failed: %w", prefix, err)
	}
	return nil
}
@mike76-dev mike76-dev changed the title unmarshalHex() panics if the submitted public key has more than 64 hex digits unmarshalHex() panics if the public key submitted to UnmarshalText() has more than 64 hex digits May 19, 2024
@lukechampine
Copy link
Member

Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants