Make DecodeBlock panic if block size is too small
Should never get a block size 9 bytes since Encode always returns the min timestampe and a 1 byte header. If we get this, the engine is confused.pull/4308/head
parent
b0449702e5
commit
cb28dabf62
|
@ -21,6 +21,10 @@ const (
|
||||||
|
|
||||||
// BlockString designates a block encodes string values
|
// BlockString designates a block encodes string values
|
||||||
BlockString = 3
|
BlockString = 3
|
||||||
|
|
||||||
|
// encodedBlockHeaderSize is the size of the header for an encoded block. The first 8 bytes
|
||||||
|
// are the minimum timestamp of the block. The next byte is a block encoding type indicator.
|
||||||
|
encodedBlockHeaderSize = 9
|
||||||
)
|
)
|
||||||
|
|
||||||
type Value interface {
|
type Value interface {
|
||||||
|
@ -120,8 +124,8 @@ func (v Values) DecodeSameTypeBlock(block []byte) Values {
|
||||||
// DecodeBlock takes a byte array and will decode into values of the appropriate type
|
// DecodeBlock takes a byte array and will decode into values of the appropriate type
|
||||||
// based on the block
|
// based on the block
|
||||||
func DecodeBlock(block []byte) (Values, error) {
|
func DecodeBlock(block []byte) (Values, error) {
|
||||||
if len(block) == 0 {
|
if len(block) <= encodedBlockHeaderSize {
|
||||||
return Values{}, nil
|
panic(fmt.Sprintf("decode of short block: got %v, exp %v", len(block), encodedBlockHeaderSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
blockType := block[8]
|
blockType := block[8]
|
||||||
|
@ -135,10 +139,8 @@ func DecodeBlock(block []byte) (Values, error) {
|
||||||
case BlockString:
|
case BlockString:
|
||||||
return decodeStringBlock(block)
|
return decodeStringBlock(block)
|
||||||
default:
|
default:
|
||||||
|
panic(fmt.Sprintf("unknown block type: %d", blockType))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add support for other block types
|
|
||||||
return nil, fmt.Errorf("unknown block type: %d", blockType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deduplicate returns a new Values slice with any values
|
// Deduplicate returns a new Values slice with any values
|
||||||
|
|
Loading…
Reference in New Issue