From 3831ae621f5b75add3ad528b1f07dd30c154fcae Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 29 Aug 2018 07:44:36 +1000 Subject: SPIGOT-4325: Validate coordinate arguments in Chunk/ChunkSnapshot --- src/main/java/org/bukkit/craftbukkit/CraftChunk.java | 9 +++++++++ .../java/org/bukkit/craftbukkit/CraftChunkSnapshot.java | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'src') 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]; } -- cgit v1.2.3