From 011cd0e4f413aa91829f9df944902adfa0b45c61 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 23 Aug 2015 22:48:54 +0200 Subject: [PATCH] Be more defensive in decoding node id table in blocks. --- common/block.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/common/block.go b/common/block.go index 18d95ad..cc9fbf2 100644 --- a/common/block.go +++ b/common/block.go @@ -176,11 +176,24 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error) offset++ numMappings := int(binary.BigEndian.Uint16(data[offset:])) offset += 2 - for i := 0; i < numMappings; i++ { + const outOfBounds = "Offset in node id table out of bounds. Ignored." + for i, n := 0, len(data); i < numMappings; i++ { + if offset+1 >= n { + log.Println(outOfBounds) + break + } nodeId := int32(binary.BigEndian.Uint16(data[offset:])) offset += 2 + if offset+1 >= n { + log.Println(outOfBounds) + break + } nameLen := int(binary.BigEndian.Uint16(data[offset:])) offset += 2 + if offset+nameLen-1 >= n { + log.Println(outOfBounds) + break + } name := string(data[offset : offset+nameLen]) offset += nameLen switch name { @@ -191,7 +204,7 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error) default: if index, found := colors.NameIndex[name]; found { indexMap[nodeId] = index - if colors.IsTransparent(index) { + if !transparent && colors.IsTransparent(index) { transparent = true } } else {