SPIGOT-4325: Validate coordinate arguments in Chunk/ChunkSnapshot

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2018-08-29 07:44:36 +10:00
parent da45a06d52
commit 3f8a87dfc5
2 changed files with 26 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import java.lang.ref.WeakReference;
import java.util.Arrays;
@@ -69,6 +70,8 @@ public class CraftChunk implements Chunk {
}
public Block getBlock(int x, int y, int z) {
validateChunkCoordinates(x, y, z);
return new CraftBlock(worldServer, new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z));
}
@@ -275,6 +278,12 @@ public class CraftChunk implements Chunk {
return temps;
}
static void validateChunkCoordinates(int x, int y, int z) {
Preconditions.checkArgument(0 <= x && x <= 15, "x out of range (expected 0-15, got %s)", x);
Preconditions.checkArgument(0 <= y && y <= 255, "y out of range (expected 0-255, got %s)", y);
Preconditions.checkArgument(0 <= z && z <= 15, "z out of range (expected 0-15, got %s)", z);
}
static {
Arrays.fill(emptySkyLight, (byte) 0xFF);
}