mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2025-01-05 20:21:59 -05:00
Add additional checks to FlexibleStorage and Chunk
This commit is contained in:
parent
c62ed6a6d9
commit
81de9b4577
2 changed files with 8 additions and 1 deletions
|
@ -35,7 +35,7 @@ public class Chunk {
|
||||||
int bitsPerEntry = in.readUnsignedByte();
|
int bitsPerEntry = in.readUnsignedByte();
|
||||||
|
|
||||||
List<BlockState> states = new ArrayList<>();
|
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++) {
|
for(int i = 0; i < stateCount; i++) {
|
||||||
states.add(BlockState.read(in));
|
states.add(BlockState.read(in));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,13 @@ public class FlexibleStorage {
|
||||||
bitsPerEntry = 4;
|
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.bitsPerEntry = bitsPerEntry;
|
||||||
this.data = Arrays.copyOf(data, data.length);
|
this.data = Arrays.copyOf(data, data.length);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue