From cae24068d4c78b74ec53705fe7a2bb5ea4f29699 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Fri, 6 Dec 2019 06:33:40 -0800 Subject: [PATCH] prevent OR on bitlists of different length (#4209) * prevent OR on bitlists of different length * prevent OR on bitlists of different length --- proto/beacon/db/attestation_container_helper.go | 3 +++ proto/beacon/db/attestation_container_helper_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/proto/beacon/db/attestation_container_helper.go b/proto/beacon/db/attestation_container_helper.go index 92ab9302f5..68376cec11 100644 --- a/proto/beacon/db/attestation_container_helper.go +++ b/proto/beacon/db/attestation_container_helper.go @@ -28,6 +28,9 @@ func NewContainerFromAttestations(atts []*ethpb.Attestation) *AttestationContain func (ac *AttestationContainer) Contains(att *ethpb.Attestation) bool { all := bitfield.NewBitlist(att.AggregationBits.Len()) for _, sp := range ac.SignaturePairs { + if all.Len() != sp.AggregationBits.Len() { + continue + } all = all.Or(sp.AggregationBits) } return all.Contains(att.AggregationBits) diff --git a/proto/beacon/db/attestation_container_helper_test.go b/proto/beacon/db/attestation_container_helper_test.go index aa4897285f..a72844331e 100644 --- a/proto/beacon/db/attestation_container_helper_test.go +++ b/proto/beacon/db/attestation_container_helper_test.go @@ -63,6 +63,16 @@ func TestAttestationContainer_Contains(t *testing.T) { contains: bitfield.Bitlist{0b01000000, 0b1}, want: false, }, + { + input: []bitfield.Bitlist{ + {0b10000001, 0b1}, + {0b10000010, 0b1}, + {0b10000100, 0b1}, + {0b10010001, 0b1}, + }, + contains: bitfield.Bitlist{0b10000000, 0b10}, // Different length. + want: false, + }, } for i, tt := range tests { t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {