From fd01d07589205dd6ef643cbfdad65ab0820bdc89 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Wed, 20 Aug 2014 15:05:04 +0200 Subject: [PATCH] Check that chunk buffer length fits in 16 bit. Change-Id: Id086a54aa8a1990c1979e747c1c02e53bed6d447 --- storage/local/delta.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/storage/local/delta.go b/storage/local/delta.go index 7d5196ff5..aea880408 100644 --- a/storage/local/delta.go +++ b/storage/local/delta.go @@ -326,7 +326,9 @@ func (c *deltaEncodedChunk) lastTime() clientmodel.Timestamp { } func (c *deltaEncodedChunk) marshal(w io.Writer) error { - // TODO: check somewhere that configured buf len cannot overflow 16 bit. + if len(c.buf) > math.MaxUint16 { + panic("chunk buffer length would overflow a 16 bit uint.") + } binary.LittleEndian.PutUint16(c.buf[deltaHeaderBufLenOffset:], uint16(len(c.buf))) n, err := w.Write(c.buf[:cap(c.buf)])