From 7c33dd963d46969d8d2c8434d1fd20bf244f9a75 Mon Sep 17 00:00:00 2001 From: Jack Dockerty Date: Thu, 11 Jan 2024 17:18:10 +0000 Subject: [PATCH] fix: implement check for series key before proceeding --- tsdb/series_file.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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)