mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-02 16:11:02 +01:00
tsdb: guard chunk length overflow in head chunk reader (#17533)
Signed-off-by: 0xkato <0xkkato@gmail.com>
This commit is contained in:
parent
c64dd612ef
commit
ae00fd45ab
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
@ -768,8 +769,25 @@ func (cdm *ChunkDiskMapper) Chunk(ref ChunkDiskMapperRef) (chunkenc.Chunk, error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if chkDataLen > uint64(math.MaxInt) {
|
||||||
|
return nil, &CorruptionErr{
|
||||||
|
Dir: cdm.dir.Name(),
|
||||||
|
FileIndex: sgmIndex,
|
||||||
|
Err: fmt.Errorf("chunk length %d exceeds supported size", chkDataLen),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chkDataLenInt := int(chkDataLen)
|
||||||
|
if chkDataLenStart > math.MaxInt-n-chkDataLenInt {
|
||||||
|
return nil, &CorruptionErr{
|
||||||
|
Dir: cdm.dir.Name(),
|
||||||
|
FileIndex: sgmIndex,
|
||||||
|
Err: fmt.Errorf("chunk data end overflows supported size (start=%d, len=%d, n=%d)", chkDataLenStart, chkDataLenInt, n),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Verify the chunk data end.
|
// Verify the chunk data end.
|
||||||
chkDataEnd := chkDataLenStart + n + int(chkDataLen)
|
chkDataEnd := chkDataLenStart + n + chkDataLenInt
|
||||||
if chkDataEnd > mmapFile.byteSlice.Len() {
|
if chkDataEnd > mmapFile.byteSlice.Len() {
|
||||||
return nil, &CorruptionErr{
|
return nil, &CorruptionErr{
|
||||||
Dir: cdm.dir.Name(),
|
Dir: cdm.dir.Name(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user