diff --git a/wal/decoder.go b/wal/decoder.go index a836ccd684a..f75c919fba6 100644 --- a/wal/decoder.go +++ b/wal/decoder.go @@ -54,6 +54,11 @@ func (d *decoder) decode(rec *walpb.Record) error { } data := make([]byte, l) if _, err = io.ReadFull(d.br, data); err != nil { + // ReadFull returns io.EOF only if no bytes were read + // the decoder should treat this as an ErrUnexpectedEOF instead. + if err == io.EOF { + err = io.ErrUnexpectedEOF + } return err } if err := rec.Unmarshal(data); err != nil { diff --git a/wal/record_test.go b/wal/record_test.go index 84b1248baf7..82849c27612 100644 --- a/wal/record_test.go +++ b/wal/record_test.go @@ -42,6 +42,7 @@ func TestReadRecord(t *testing.T) { }{ {infoRecord, &walpb.Record{Type: 1, Crc: crc32.Checksum(infoData, crcTable), Data: infoData}, nil}, {[]byte(""), &walpb.Record{}, io.EOF}, + {infoRecord[:8], &walpb.Record{}, io.ErrUnexpectedEOF}, {infoRecord[:len(infoRecord)-len(infoData)-8], &walpb.Record{}, io.ErrUnexpectedEOF}, {infoRecord[:len(infoRecord)-len(infoData)], &walpb.Record{}, io.ErrUnexpectedEOF}, {infoRecord[:len(infoRecord)-8], &walpb.Record{}, io.ErrUnexpectedEOF},