mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Fix double-delta unmarshaling to respect actual min header size
Turns out its valid to have an overall chunk which is smaller than the full doubleDeltaHeaderBytes size -- if it has a single sample, it doesn't fill the whole header. Updated unmarshalling check to respect this.
This commit is contained in:
parent
b815956341
commit
f50f656a66
|
@ -87,7 +87,7 @@ func TestUnmarshalingCorruptedDoubleDeltaReturnsAnError(t *testing.T) {
|
||||||
cs[0].marshalToBuf(buf)
|
cs[0].marshalToBuf(buf)
|
||||||
|
|
||||||
// Corrupt the length to be every possible too-small value
|
// Corrupt the length to be every possible too-small value
|
||||||
for i := 0; i < doubleDeltaHeaderBytes; i++ {
|
for i := 0; i < doubleDeltaHeaderMinBytes; i++ {
|
||||||
|
|
||||||
binary.LittleEndian.PutUint16(buf[doubleDeltaHeaderBufLenOffset:], uint16(i))
|
binary.LittleEndian.PutUint16(buf[doubleDeltaHeaderBufLenOffset:], uint16(i))
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,8 @@ import (
|
||||||
// - base time delta: 8 bytes
|
// - base time delta: 8 bytes
|
||||||
// - base value delta: 8 bytes
|
// - base value delta: 8 bytes
|
||||||
const (
|
const (
|
||||||
doubleDeltaHeaderBytes = 37
|
doubleDeltaHeaderBytes = 37
|
||||||
|
doubleDeltaHeaderMinBytes = 21 // header isn't full for chunk w/ one sample
|
||||||
|
|
||||||
doubleDeltaHeaderBufLenOffset = 0
|
doubleDeltaHeaderBufLenOffset = 0
|
||||||
doubleDeltaHeaderTimeBytesOffset = 2
|
doubleDeltaHeaderTimeBytesOffset = 2
|
||||||
|
@ -250,8 +251,8 @@ func (c *doubleDeltaEncodedChunk) unmarshal(r io.Reader) error {
|
||||||
if int(l) > cap(*c) {
|
if int(l) > cap(*c) {
|
||||||
return fmt.Errorf("chunk length exceeded during unmarshaling: %d", l)
|
return fmt.Errorf("chunk length exceeded during unmarshaling: %d", l)
|
||||||
}
|
}
|
||||||
if int(l) < doubleDeltaHeaderBytes {
|
if int(l) < doubleDeltaHeaderMinBytes {
|
||||||
return fmt.Errorf("chunk length less than header size: %d < %d", l, doubleDeltaHeaderBytes)
|
return fmt.Errorf("chunk length less than header size: %d < %d", l, doubleDeltaHeaderMinBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
*c = (*c)[:l]
|
*c = (*c)[:l]
|
||||||
|
@ -266,8 +267,8 @@ func (c *doubleDeltaEncodedChunk) unmarshalFromBuf(buf []byte) error {
|
||||||
if int(l) > cap(*c) {
|
if int(l) > cap(*c) {
|
||||||
return fmt.Errorf("chunk length exceeded during unmarshaling: %d", l)
|
return fmt.Errorf("chunk length exceeded during unmarshaling: %d", l)
|
||||||
}
|
}
|
||||||
if int(l) < doubleDeltaHeaderBytes {
|
if int(l) < doubleDeltaHeaderMinBytes {
|
||||||
return fmt.Errorf("chunk length less than header size: %d < %d", l, doubleDeltaHeaderBytes)
|
return fmt.Errorf("chunk length less than header size: %d < %d", l, doubleDeltaHeaderMinBytes)
|
||||||
}
|
}
|
||||||
*c = (*c)[:l]
|
*c = (*c)[:l]
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue