Skip to content

Commit

Permalink
fix: for critical issue #19916 (influxdb server crashed when reading …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
gggevorgyan authored and Gevorg Gevorgyan committed Feb 19, 2024
1 parent 589d278 commit 4233042
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tsdb/engine/tsm1/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

Expand Down

0 comments on commit 4233042

Please sign in to comment.