From f45607207b3539b3732e611e7ed4b41180a29b8b Mon Sep 17 00:00:00 2001 From: gggevorgyan Date: Wed, 11 Jan 2023 11:46:58 +0400 Subject: [PATCH] Fix for critical issue #19916 (influxdb server crashed when reading a corrupt file) Added check on indexOfsStart, to make index slice length fit in int32, and count should have >0 value otherwise it is corruption. - [ ] CHANGELOG.md updated - [*] Rebased/mergable - [*] Tests pass - [*] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed) --- tsdb/engine/tsm1/reader.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tsdb/engine/tsm1/reader.go b/tsdb/engine/tsm1/reader.go index 424f35f0629..306e7b21f34 100644 --- a/tsdb/engine/tsm1/reader.go +++ b/tsdb/engine/tsm1/reader.go @@ -1233,6 +1233,10 @@ func (d *indirectIndex) UnmarshalBinary(b []byte) error { return fmt.Errorf("indirectIndex: not enough data for index entries count") } count := int32(binary.BigEndian.Uint16(b[i : i+indexCountSize])) + + if count <= 0 { + return fmt.Errorf("indirectIndex: the count should have >0 value") + } i += indexCountSize // Find the min time for the block @@ -1350,7 +1354,7 @@ func (m *mmapAccessor) init() (*indirectIndex, error) { indexOfsPos := len(m.b) - 8 indexStart := binary.BigEndian.Uint64(m.b[indexOfsPos : indexOfsPos+8]) - if indexStart >= uint64(indexOfsPos) { + if indexStart >= uint64(indexOfsPos) || (uint64(indexOfsPos)-indexStart) > math.MaxInt32 { return nil, fmt.Errorf("mmapAccessor: invalid indexStart") }