Skip to content

chunk.NetworkDecode and (*chunk.Chunk).SetBlock panic on certain data #1024

@HashimTheArab

Description

@HashimTheArab

SetBlock Panic

func (w *World) SetBlockByRuntimeID(pos cube.Pos, blockID uint32) {
	if cube.Pos(pos).OutOfBounds(cube.Range(w.Dimension().Range())) {
		return
	}

	chunkPos := protocol.ChunkPos{int32(pos[0]) >> 4, int32(pos[2]) >> 4}
	c := w.Chunk(chunkPos) // This returns a dragonfly *chunk.Chunk
	if c == nil {
		return
	}

	c.SetBlock(uint8(pos[0]), int16(pos[1]), uint8(pos[2]), 0, blockID) // This line panics
}
case *packet.UpdateBlock:
	rid := pk.NewBlockRuntimeID
	_, ok := world.BlockByRuntimeID(rid)
	if !ok {
		rid = airRuntimeID
	}

	pos := cube.Pos{int(pk.Position.X()), int(pk.Position.Y()), int(pk.Position.Z())}
	p.player.World().SetBlockByRuntimeID(pos, rid)

github.com/df-mc/dragonfly/server/world/chunk in (*Chunk).SetBlock at line 88
runtime error: index out of range [-1]

sub := chunk.sub[chunk.SubIndex(y)]

chunk.NetworkDecode panic

chunk.NetworkDecode panic: runtime error: index out of range [109] with length 24

case *packet.LevelChunk:
	dim := dimensionFromNetworkID(pk.Dimension)

	c, err := chunk.NetworkDecode(airRuntimeID, pk.RawPayload, int(pk.SubChunkCount), dim.Range())
	if err != nil {
	 	c = chunk.New(airRuntimeID, dim.Range())
	}

github.com/df-mc/dragonfly/server/world/chunk in NetworkDecode at line 24

c.sub[index], err = decodeSubChunk(buf, c, &index, NetworkEncoding)

I have many logs of chunk data from these crashes, here's a log of *packet.LevelChunk
https://gist.github.com/HashimTheArab/1ebab2a39a22d8af009987d96b598a24

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions