diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/Chunk.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/Chunk.java index d9610034..e68d86f0 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/Chunk.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/Chunk.java @@ -35,7 +35,7 @@ public class Chunk { int bitsPerEntry = in.readUnsignedByte(); List states = new ArrayList<>(); - int stateCount = bitsPerEntry > 8 ? 0 : in.readVarInt(); + int stateCount = (bitsPerEntry > 8 || bitsPerEntry == 0) ? 0 : in.readVarInt(); for(int i = 0; i < stateCount; i++) { states.add(BlockState.read(in)); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/FlexibleStorage.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/FlexibleStorage.java index e1b6cb16..0526682e 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/FlexibleStorage.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/FlexibleStorage.java @@ -21,6 +21,13 @@ public class FlexibleStorage { bitsPerEntry = 4; } + char valuesPerLong = (char) (64 / bitsPerEntry); + int expectedLength = (4096 + valuesPerLong - 1) / valuesPerLong; + + if (data.length != expectedLength) { + throw new IllegalArgumentException("Got " + data.length + " as the chunk data length, but was expecting " + expectedLength); + } + this.bitsPerEntry = bitsPerEntry; this.data = Arrays.copyOf(data, data.length);