Skip to content

Commit

Permalink
fix: bounds-checking and partial write handling
Browse files Browse the repository at this point in the history
  • Loading branch information
davidby-influx committed Dec 7, 2023
1 parent e82ffeb commit ee0572e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tsdb/series_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (s *SeriesSegment) MaxSeriesID() uint64 {
// ForEachEntry executes fn for every entry in the segment.
func (s *SeriesSegment) ForEachEntry(fn func(flag uint8, id uint64, offset int64, key []byte) error) error {
for pos := uint32(SeriesSegmentHeaderSize); pos < s.size; {
flag, id, key, sz := ReadSeriesEntry(s.data[pos:s.size])
flag, id, key, sz := ReadSeriesEntry(s.data[pos:])
if !IsValidSeriesEntryFlag(flag) {
break
}
Expand Down Expand Up @@ -424,6 +424,9 @@ func (hdr *SeriesSegmentHeader) WriteTo(w io.Writer) (n int64, err error) {
}

func ReadSeriesEntry(data []byte) (flag uint8, id uint64, key []byte, sz int64) {
if len(data) <= 0 {
return 0, 0, nil, 1
}
// If flag byte is zero then no more entries exist.
flag, data = uint8(data[0]), data[1:]
if !IsValidSeriesEntryFlag(flag) {
Expand Down

0 comments on commit ee0572e

Please sign in to comment.