mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Validate index TOC checksum on read
This commit is contained in:
parent
6ca5e52b69
commit
4fdf9b195c
|
@ -2,7 +2,7 @@
|
|||
|
||||
The following describes the format of a single chunks file, which is created in the `chunks/` directory of a block. The maximum size per segment file is 512MiB.
|
||||
|
||||
Chunks in the files are referenced from the index by the in-file offset in the 4 LSB and the segment sequence number in the bigher 4 MSBs.
|
||||
Chunks in the files are referenced from the index by the in-file offset in the 4 LSB and the segment sequence number in the higher 4 MSBs.
|
||||
|
||||
```
|
||||
┌────────────────────────────────────────┬──────────────────────┐
|
||||
|
|
2
block.go
2
block.go
|
@ -133,7 +133,7 @@ func writeMetaFile(dir string, meta *BlockMeta) error {
|
|||
return renameFile(tmp, path)
|
||||
}
|
||||
|
||||
// Block represents a directory of time series data covering a continous time range.
|
||||
// Block represents a directory of time series data covering a continuous time range.
|
||||
type Block struct {
|
||||
mtx sync.RWMutex
|
||||
closing bool
|
||||
|
|
13
index.go
13
index.go
|
@ -575,6 +575,7 @@ type indexReader struct {
|
|||
var (
|
||||
errInvalidSize = fmt.Errorf("invalid size")
|
||||
errInvalidFlag = fmt.Errorf("invalid flag")
|
||||
errInvalidChecksum = fmt.Errorf("invalid checksum")
|
||||
)
|
||||
|
||||
// NewIndexReader returns a new IndexReader on the given directory.
|
||||
|
@ -618,6 +619,11 @@ func newIndexReader(dir string) (*indexReader, error) {
|
|||
func (r *indexReader) readTOC() error {
|
||||
d := r.decbufAt(len(r.b) - indexTOCLen)
|
||||
|
||||
crc := newCRC32()
|
||||
if _, err := crc.Write(d.get()[:d.len()-4]); err != nil {
|
||||
return errors.Wrap(err, "write to hash")
|
||||
}
|
||||
|
||||
r.toc.symbols = d.be64()
|
||||
r.toc.series = d.be64()
|
||||
r.toc.labelIndices = d.be64()
|
||||
|
@ -625,9 +631,12 @@ func (r *indexReader) readTOC() error {
|
|||
r.toc.postings = d.be64()
|
||||
r.toc.postingsTable = d.be64()
|
||||
|
||||
// TODO(fabxc): validate checksum.
|
||||
// Validate checksum
|
||||
if d.be32() != crc.Sum32() {
|
||||
return errors.Wrap(errInvalidChecksum, "TOC checksum")
|
||||
}
|
||||
|
||||
return nil
|
||||
return d.err()
|
||||
}
|
||||
|
||||
func (r *indexReader) decbufAt(off int) decbuf {
|
||||
|
|
Loading…
Reference in a new issue