influxdata / influxdata/influxdb
influxdb server crashed when reading a corrupt file
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
__Steps to reproduce:__
List the minimal actions needed to reproduce the behavior.
It‘s not easy to procedure because it is caused by file system error
__Expected behavior:__
Successfully reading the corrupt tsm file and return error info
__Actual behavior:__
the server crashed and throw slice bounds out of range error
__Environment info:__
* System info: centos 7
* InfluxDB version: from 1.7 to 2.0
__Logs:__
Include snippet of errors in log.
s=2020-10-30T15:06:52.317091Z lvl=info msg="Opened file" log_id=0QAWWAwG000 engine=tsm1 service=filestore path=XXX/autogen/45/000000072-000000002.tsm id=12 duration=74931.498ms
panic: runtime error: slice bounds out of range
goroutine 9075 [running]:
github.com/influxdata/influxdb/tsdb/engine/tsm1.(*indirectIndex).UnmarshalBinary(0xc072082b40, 0xc5c0000000, 0x703f04fe, 0x703f04fe, 0x0, 0x0)
I have found the crash reason:
In the function indirectIndex.UnmarshalBinary of reader.go
`
func (d *indirectIndex) UnmarshalBinary(b []byte) error {...
for i < iMax {
...
//1、 count maybe get a value zero
count := int32(binary.BigEndian.Uint16(b[i : i+indexCountSize]))
...
//2、 and then i will be a negative number
...
//3、slice bounds out of range here
maxT := int64(binary.BigEndian.Uint64(b[i+8 : i+16]))
if maxT > maxTime {
maxTime = maxT
}
i += indexEntrySize
}
...`
Contributor guide
Research direction
Start in tsdb/engine/tsm1/reader.go at indirectIndex.UnmarshalBinary and inspect how the corrupt TSM data affects count and the index bounds. Reproduce with the corrupt TSM file or equivalent malformed input described in the issue, then verify that reading returns error information instead of panicking with a slice-bounds error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100