From 3cda841bed68e55d9f29c1e5023601eafbe39737 Mon Sep 17 00:00:00 2001 From: Tnze Date: Sat, 25 Jun 2022 23:02:36 +0800 Subject: [PATCH] Check chunk data index and no longer panic --- level/chunk.go | 3 +++ save/chunk.go | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/level/chunk.go b/level/chunk.go index 383f5b0..1c97cdb 100644 --- a/level/chunk.go +++ b/level/chunk.go @@ -143,6 +143,9 @@ func ChunkFromSave(c *save.Chunk) (*Chunk, error) { sections := make([]Section, secs) for _, v := range c.Sections { i := int32(v.Y) - c.YPos + if i < 0 || i >= int32(secs) { + return nil, fmt.Errorf("section Y value %d out of bounds", v.Y) + } var err error sections[i].BlockCount, sections[i].States, err = readStatesPalette(v.BlockStates.Palette, v.BlockStates.Data) if err != nil { diff --git a/save/chunk.go b/save/chunk.go index 9975f2e..d931087 100644 --- a/save/chunk.go +++ b/save/chunk.go @@ -13,11 +13,11 @@ import ( // Chunk is 16* chunk type Chunk struct { DataVersion int32 - XPos int32 `nbt:"xPos"` - YPos int32 `nbt:"yPos"` - ZPos int32 `nbt:"zPos"` - BlockEntities nbt.RawMessage `nbt:"block_entities"` - Structures nbt.RawMessage `nbt:"structures"` + XPos int32 `nbt:"xPos"` + YPos int32 `nbt:"yPos"` + ZPos int32 `nbt:"zPos"` + BlockEntities []nbt.RawMessage `nbt:"block_entities"` + Structures nbt.RawMessage `nbt:"structures"` Heightmaps struct { MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"` MotionBlockingNoLeaves []uint64 `nbt:"MOTION_BLOCKING_NO_LEAVES"`