13
0
geforkt von Mirrors/Paper

SPIGOT-4325: Validate coordinate arguments in Chunk/ChunkSnapshot

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2018-08-29 07:44:36 +10:00
Ursprung da45a06d52
Commit 3f8a87dfc5
2 geänderte Dateien mit 26 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,6 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Arrays; import java.util.Arrays;
@ -69,6 +70,8 @@ public class CraftChunk implements Chunk {
} }
public Block getBlock(int x, int y, int z) { 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)); 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; 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 { static {
Arrays.fill(emptySkyLight, (byte) 0xFF); Arrays.fill(emptySkyLight, (byte) 0xFF);
} }

Datei anzeigen

@ -1,5 +1,6 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
@ -57,38 +58,54 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
@Override @Override
public Material getBlockType(int x, int y, int z) { 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()); return CraftMagicNumbers.getMaterial(blockids[y >> 4].a(x, y & 0xF, z).getBlock());
} }
@Override @Override
public final BlockData getBlockData(int x, int y, int z) { 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)); return CraftBlockData.fromData(blockids[y >> 4].a(x, y & 0xF, z));
} }
@Override @Override
public final int getData(int x, int y, int z) { 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)); return CraftMagicNumbers.toLegacyData(blockids[y >> 4].a(x, y & 0xF, z));
} }
public final int getBlockSkyLight(int x, int y, int 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); int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
return (skylight[y >> 4][off] >> ((x & 1) << 2)) & 0xF; return (skylight[y >> 4][off] >> ((x & 1) << 2)) & 0xF;
} }
public final int getBlockEmittedLight(int x, int y, int z) { public final int getBlockEmittedLight(int x, int y, int z) {
CraftChunk.validateChunkCoordinates(x, y, z);
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1); int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
return (emitlight[y >> 4][off] >> ((x & 1) << 2)) & 0xF; return (emitlight[y >> 4][off] >> ((x & 1) << 2)) & 0xF;
} }
public final int getHighestBlockYAt(int x, int z) { public final int getHighestBlockYAt(int x, int z) {
CraftChunk.validateChunkCoordinates(x, 0, z);
return hmap.a(x, z); return hmap.a(x, z);
} }
public final Biome getBiome(int x, int z) { public final Biome getBiome(int x, int z) {
CraftChunk.validateChunkCoordinates(x, 0, z);
return CraftBlock.biomeBaseToBiome(biome[z << 4 | x]); return CraftBlock.biomeBaseToBiome(biome[z << 4 | x]);
} }
public final double getRawBiomeTemperature(int x, int z) { public final double getRawBiomeTemperature(int x, int z) {
CraftChunk.validateChunkCoordinates(x, 0, z);
return biomeTemp[z << 4 | x]; return biomeTemp[z << 4 | x];
} }