diff --git a/tsdb/series_file.go b/tsdb/series_file.go index 59c45568e8f..c1b6bed1f87 100644 --- a/tsdb/series_file.go +++ b/tsdb/series_file.go @@ -22,7 +22,6 @@ import ( var ( ErrSeriesFileClosed = errors.New("tsdb: series file closed") ErrInvalidSeriesPartitionID = errors.New("tsdb: invalid series partition id") - // ErrInvalidMeasurement = errors.New("tsdb: invalid measurement for series key provided") ) // SeriesIDSize is the size in bytes of a series key ID. @@ -378,9 +377,6 @@ func ReadSeriesKeyLen(data []byte) (sz int, remainder []byte) { } func ReadSeriesKeyMeasurement(data []byte) (name, remainder []byte) { - if len(data) < 2 { - // return nil, nil, ErrInvalidMeasurement - } n, data := binary.BigEndian.Uint16(data), data[2:] return data[:n], data[n:] } @@ -417,7 +413,11 @@ func ParseSeriesKeyInto(data []byte, dstTags models.Tags) ([]byte, models.Tags) // different length and capacity to those provided. func parseSeriesKey(data []byte, dst models.Tags) ([]byte, models.Tags) { var name []byte - _, data = ReadSeriesKeyLen(data) + sz, data := ReadSeriesKeyLen(data) + // Ensure that the seriesKey is valid before proceeding to subsequent calls. + if sz == 0 && len(data) == 0 { + return nil, nil + } name, data = ReadSeriesKeyMeasurement(data) tagN, data := ReadSeriesKeyTagN(data)