diff --git a/replication/event.go b/replication/event.go index 6fb614f61..470e849bd 100644 --- a/replication/event.go +++ b/replication/event.go @@ -234,8 +234,17 @@ func (e *PreviousGTIDsEvent) Decode(data []byte) error { uuidCount := binary.LittleEndian.Uint16(data[pos : pos+8]) pos += 8 + if uuidCount <= 1 { + if len(data) == 8 { + return nil + } + } + previousGTIDSets := make([]string, uuidCount) for i := range previousGTIDSets { + if len(data) < pos+16 { + return fmt.Errorf("Failed to decode UUID") + } uuid := e.decodeUuid(data[pos : pos+16]) pos += 16 sliceCount := binary.LittleEndian.Uint16(data[pos : pos+8]) diff --git a/replication/event_test.go b/replication/event_test.go index 1333cd5ef..83fedaa5f 100644 --- a/replication/event_test.go +++ b/replication/event_test.go @@ -140,3 +140,11 @@ func TestIntVarEvent(t *testing.T) { require.Equal(t, INSERT_ID, ev.Type) require.Equal(t, uint64(23), ev.Value) } + +func TestPreviousGTIDEvent(t *testing.T) { + // uuidCount == 1 + data := []byte{1, 0, 0, 0, 0, 0, 0, 1} + ev := PreviousGTIDsEvent{} + err := ev.Decode(data) + require.NoError(t, err) +}