Be more defensive in decoding node id table in blocks.

This commit is contained in:
Sascha L. Teichmann 2015-08-23 22:48:54 +02:00
parent dc2845abb1
commit 011cd0e4f4
1 changed files with 15 additions and 2 deletions

View File

@ -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 {