diff options
author | Mike Primm <mike@primmhome.com> | 2013-04-15 15:51:18 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2013-04-15 22:50:20 -0500 |
commit | 40e630871855255c14c78beaf8c63e7aa6b3c930 (patch) | |
tree | 09d44ab928f488d5525d9140152f1932f09a5669 /src/main/java/net/minecraft | |
parent | 928e4d9bbb9f47bc11a89cd3a537dcc651f2b33a (diff) | |
download | craftbukkit-40e630871855255c14c78beaf8c63e7aa6b3c930.tar craftbukkit-40e630871855255c14c78beaf8c63e7aa6b3c930.tar.gz craftbukkit-40e630871855255c14c78beaf8c63e7aa6b3c930.tar.lz craftbukkit-40e630871855255c14c78beaf8c63e7aa6b3c930.tar.xz craftbukkit-40e630871855255c14c78beaf8c63e7aa6b3c930.zip |
Validate chunk data array lengths. Fixes BUKKIT-4093
If a chunk has somehow managed to save with arrays that are not 4096
entries long when reading them again we will get exceptions. Checking the
array length and resizing if needed is cheap so we should do this to help
avoid crashing servers due to this error.
Diffstat (limited to 'src/main/java/net/minecraft')
-rw-r--r-- | src/main/java/net/minecraft/server/ChunkSection.java | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java index 38f3038d..bac819f2 100644 --- a/src/main/java/net/minecraft/server/ChunkSection.java +++ b/src/main/java/net/minecraft/server/ChunkSection.java @@ -219,7 +219,7 @@ public class ChunkSection { } public void a(byte[] abyte) { - this.blockIds = abyte; + this.blockIds = this.validateByteArray(abyte); // CraftBukkit - Validate data } public void a(NibbleArray nibblearray) { @@ -237,18 +237,40 @@ public class ChunkSection { } // CraftBukkit end - this.extBlockIds = nibblearray; + this.extBlockIds = this.validateNibbleArray(nibblearray); // CraftBukkit - Validate data } public void b(NibbleArray nibblearray) { - this.blockData = nibblearray; + this.blockData = this.validateNibbleArray(nibblearray); // CraftBukkit - Validate data } public void c(NibbleArray nibblearray) { - this.blockLight = nibblearray; + this.blockLight = this.validateNibbleArray(nibblearray); // CraftBukkit - Validate data } public void d(NibbleArray nibblearray) { - this.skyLight = nibblearray; + this.skyLight = this.validateNibbleArray(nibblearray); // CraftBukkit - Validate data } + + // CraftBukkit start - Validate array lengths + private NibbleArray validateNibbleArray(NibbleArray nibbleArray) { + if (nibbleArray != null && nibbleArray.a.length < 2048) { + byte[] newArray = new byte[2048]; + System.arraycopy(nibbleArray.a, 0, newArray, 0, ((nibbleArray.a.length > 2048) ? 2048 : nibbleArray.a.length)); + nibbleArray = new NibbleArray(newArray, 4); + } + + return nibbleArray; + } + + private byte[] validateByteArray(byte[] byteArray) { + if (byteArray != null && byteArray.length < 4096) { + byte[] newArray = new byte[4096]; + System.arraycopy(byteArray, 0, newArray, 0, byteArray.length); + byteArray = newArray; + } + + return byteArray; + } + // CraftBukkit end } |