From de8a49d40af7eb33d8c335d9263af95702f4bf6b Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Sat, 5 May 2018 21:18:54 +0200 Subject: [PATCH] btcec: Avoid panic in FieldVal.SetByteSlice When called with a value larger than 32 bytes. --- btcec/field.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/btcec/field.go b/btcec/field.go index 0f2be74c0c..b4f9bf7435 100644 --- a/btcec/field.go +++ b/btcec/field.go @@ -220,6 +220,10 @@ func (f *fieldVal) SetBytes(b *[32]byte) *fieldVal { // The field value is returned to support chaining. This enables syntax like: // f := new(fieldVal).SetByteSlice(byteSlice) func (f *fieldVal) SetByteSlice(b []byte) *fieldVal { + if len(b) > 32 { + b = b[:32] + } + var b32 [32]byte for i := 0; i < len(b); i++ { if i < 32 {