summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-08-29 07:44:36 +1000
committermd_5 <git@md-5.net>2018-08-29 07:44:36 +1000
commit3831ae621f5b75add3ad528b1f07dd30c154fcae (patch)
tree9358fddc997e2c94e07d05e0f9c52daf0ccc383b /src
parenta1ab86d8cb5e264c2a4032c3729407534d21d33a (diff)
downloadcraftbukkit-3831ae621f5b75add3ad528b1f07dd30c154fcae.tar
craftbukkit-3831ae621f5b75add3ad528b1f07dd30c154fcae.tar.gz
craftbukkit-3831ae621f5b75add3ad528b1f07dd30c154fcae.tar.lz
craftbukkit-3831ae621f5b75add3ad528b1f07dd30c154fcae.tar.xz
craftbukkit-3831ae621f5b75add3ad528b1f07dd30c154fcae.zip
SPIGOT-4325: Validate coordinate arguments in Chunk/ChunkSnapshot
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftChunk.java9
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java17
2 files changed, 26 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
index b0297c64..6424572f 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
@@ -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);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
index 8032f358..f3be8c20 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit;
+import com.google.common.base.Preconditions;
import org.bukkit.ChunkSnapshot;
import org.bukkit.Material;
import org.bukkit.block.Biome;
@@ -57,38 +58,54 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
@Override
public Material getBlockType(int x, int y, int z) {
+ CraftChunk.validateChunkCoordinates(x, y, z);
+
return CraftMagicNumbers.getMaterial(blockids[y >> 4].a(x, y & 0xF, z).getBlock());
}
@Override
public final BlockData getBlockData(int x, int y, int z) {
+ CraftChunk.validateChunkCoordinates(x, y, z);
+
return CraftBlockData.fromData(blockids[y >> 4].a(x, y & 0xF, z));
}
@Override
public final int getData(int x, int y, int z) {
+ CraftChunk.validateChunkCoordinates(x, y, z);
+
return CraftMagicNumbers.toLegacyData(blockids[y >> 4].a(x, y & 0xF, z));
}
public final int getBlockSkyLight(int x, int y, int z) {
+ CraftChunk.validateChunkCoordinates(x, y, z);
+
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
return (skylight[y >> 4][off] >> ((x & 1) << 2)) & 0xF;
}
public final int getBlockEmittedLight(int x, int y, int z) {
+ CraftChunk.validateChunkCoordinates(x, y, z);
+
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
return (emitlight[y >> 4][off] >> ((x & 1) << 2)) & 0xF;
}
public final int getHighestBlockYAt(int x, int z) {
+ CraftChunk.validateChunkCoordinates(x, 0, z);
+
return hmap.a(x, z);
}
public final Biome getBiome(int x, int z) {
+ CraftChunk.validateChunkCoordinates(x, 0, z);
+
return CraftBlock.biomeBaseToBiome(biome[z << 4 | x]);
}
public final double getRawBiomeTemperature(int x, int z) {
+ CraftChunk.validateChunkCoordinates(x, 0, z);
+
return biomeTemp[z << 4 | x];
}