Add additional checks to FlexibleStorage and Chunk

This commit is contained in:
RednedEpic 2020-05-21 18:39:52 -05:00
parent c62ed6a6d9
commit 81de9b4577
2 changed files with 8 additions and 1 deletions

View file

@ -35,7 +35,7 @@ public class Chunk {
int bitsPerEntry = in.readUnsignedByte();
List<BlockState> 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));
}

View file

@ -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);