mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
Be more defensive in decoding node id table in blocks.
This commit is contained in:
parent
dc2845abb1
commit
011cd0e4f4
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user