SiaFoundation / core

Core packages for the Sia project
MIT License
51 stars 7 forks source link

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

Closed mike76-dev closed 1 month ago

mike76-dev commented 2 months ago

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
}
lukechampine commented 1 month ago

Good catch!