testserver/Spigot-Server-Patches/0361-Allow-Saving-of-Oversi...

511 lines
24 KiB
Diff
Raw Normal View History

2019-05-06 20:45:02 +00:00
From 474d222e2b8dde31dc97fb3a077f44a82b5f2b20 Mon Sep 17 00:00:00 2001
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
From: Aikar <aikar@aikar.co>
Date: Fri, 15 Feb 2019 01:08:19 -0500
Subject: [PATCH] Allow Saving of Oversized Chunks
The Minecraft World Region File format has a hard cap of 1MB per chunk.
This is due to the fact that the header of the file format only allocates
a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector.
This limit can be reached fairly easily with books, resulting in the chunk being unable
to save to the world. Worse off, is that nothing printed when this occured, and silently
performed a chunk rollback on next load.
This leads to security risk with duplication and is being actively exploited.
This patch catches the too large scenario, falls back and moves any large Entity
or Tile Entity into a new compound, and this compound is saved into a different file.
On Chunk Load, we check for oversized status, and if so, we load the extra file and
merge the Entities and Tile Entities from the oversized chunk back into the level to
then be loaded as normal.
Once a chunk is returned back to normal size, the oversized flag will clear, and no
extra data file will exist.
This fix maintains compatability with all existing Anvil Region Format tools as it
does not alter the save format. They will just not know about the extra entities.
This fix also maintains compatability if someone switches server jars to one without
this fix, as the data will remain in the oversized file. Once the server returns
to a jar with this fix, the data will be restored.
diff --git a/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java b/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
2019-05-05 17:19:34 +00:00
index 9fd8a75dae..d49afd622e 100644
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
--- a/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
+++ b/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
2019-05-05 17:19:34 +00:00
@@ -69,6 +69,7 @@ public class NBTCompressedStreamTools {
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
}
+ public static NBTTagCompound readNBT(DataInputStream datainputstream) throws IOException { return a(datainputstream); } // Paper - OBFHELPER
public static NBTTagCompound a(DataInputStream datainputstream) throws IOException {
return a((DataInput) datainputstream, NBTReadLimiter.a);
}
2019-05-05 17:19:34 +00:00
@@ -89,6 +90,7 @@ public class NBTCompressedStreamTools {
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
}
}
+ public static void writeNBT(NBTTagCompound nbttagcompound, DataOutput dataoutput) throws IOException { a(nbttagcompound, dataoutput); } // Paper - OBFHELPER
public static void a(NBTTagCompound nbttagcompound, DataOutput dataoutput) throws IOException {
a((NBTBase) nbttagcompound, dataoutput);
}
2019-05-05 17:19:34 +00:00
diff --git a/src/main/java/net/minecraft/server/NBTTagList.java b/src/main/java/net/minecraft/server/NBTTagList.java
index b7c94fe238..80eea5dfbd 100644
--- a/src/main/java/net/minecraft/server/NBTTagList.java
+++ b/src/main/java/net/minecraft/server/NBTTagList.java
@@ -11,7 +11,7 @@ import java.util.Objects;
public class NBTTagList extends NBTList<NBTBase> {
- private List<NBTBase> list = Lists.newArrayList();
+ List<NBTBase> list = Lists.newArrayList(); // Paper - private -> package
private byte type = 0;
public NBTTagList() {}
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
2019-05-06 20:45:02 +00:00
index e68f901943..ed2ccebb23 100644
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
2019-05-05 17:19:34 +00:00
@@ -23,7 +23,7 @@ public class RegionFile implements AutoCloseable {
// Minecraft is limited to 256 sections per chunk. So 1MB. This can easily be overriden.
// So we extend this to use the REAL size when the count is maxed by seeking to that section and reading the length.
private static final boolean ENABLE_EXTENDED_SAVE = Boolean.parseBoolean(System.getProperty("net.minecraft.server.RegionFile.enableExtendedSave", "true"));
- private final File file;
+ final File file; // Paper - private -> package
// Spigot end
private static final byte[] a = new byte[4096];
private final RandomAccessFile b; private RandomAccessFile getDataFile() { return this.b; } // Paper - OBFHELPER
2019-05-06 20:45:02 +00:00
@@ -33,6 +33,7 @@ public class RegionFile implements AutoCloseable {
public RegionFile(File file) throws IOException {
this.b = new RandomAccessFile(file, "rw");
+ this.file = file; // Spigot // Paper - We need this earlier
if (this.b.length() < 8192L) { // Paper - headers should be 8192
this.b.write(RegionFile.a);
this.b.write(RegionFile.a);
@@ -66,6 +67,7 @@ public class RegionFile implements AutoCloseable {
2019-05-05 17:19:34 +00:00
}
header.clear();
java.nio.IntBuffer headerAsInts = header.asIntBuffer();
+ initOversizedState();
// Paper End
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
2019-05-05 17:19:34 +00:00
int k;
2019-05-06 20:45:02 +00:00
@@ -83,7 +85,7 @@ public class RegionFile implements AutoCloseable {
2019-05-05 17:19:34 +00:00
this.b.seek(j * 4 + 4); // Go back to where we were
}
2019-05-05 17:19:34 +00:00
}
- if (k > 0 && (k >> 8) > 1 && (k >> 8) + (k & 255) <= this.e.size()) { // Paper >= 1 as 0/1 are the headers, and negative isnt valid
+ if (k > 0 && (k >> 8) > 1 && (k >> 8) + (length) <= this.e.size()) { // Paper >= 1 as 0/1 are the headers, and negative isnt valid
for (int l = 0; l < (length); ++l) {
// Spigot end
this.e.set((k >> 8) + l, false);
2019-05-06 20:45:02 +00:00
@@ -102,11 +104,11 @@ public class RegionFile implements AutoCloseable {
if (offsets[j] != 0) this.timestamps[j] = k; // Paper - don't set timestamp if it got 0'd above due to corruption
}
- this.file = file; // Spigot
+ // Paper - we need this earlier
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
}
@Nullable
2019-05-05 17:19:34 +00:00
- public synchronized DataInputStream a(ChunkCoordIntPair chunkcoordintpair) {
+ public synchronized DataInputStream getReadStream(ChunkCoordIntPair chunkcoordintpair) { return this.a(chunkcoordintpair); } public synchronized DataInputStream a(ChunkCoordIntPair chunkcoordintpair) { // Paper - OBFHELPER
try {
int i = this.getOffset(chunkcoordintpair);
2019-05-06 20:45:02 +00:00
@@ -182,8 +184,8 @@ public class RegionFile implements AutoCloseable {
2019-05-05 17:19:34 +00:00
}
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
}
2019-05-05 17:19:34 +00:00
- public DataOutputStream c(ChunkCoordIntPair chunkcoordintpair) {
- return new DataOutputStream(new BufferedOutputStream(new DeflaterOutputStream(new RegionFile.ChunkBuffer(chunkcoordintpair))));
+ public DataOutputStream getWriteStream(ChunkCoordIntPair chunkcoordintpair) { return this.c(chunkcoordintpair); } public DataOutputStream c(ChunkCoordIntPair chunkcoordintpair) { // Paper - OBFHELPER
+ return new DataOutputStream(new RegionFile.ChunkBuffer(chunkcoordintpair)); // Paper - remove middleware, move deflate to .close() for dynamic levels
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
}
2019-05-05 17:19:34 +00:00
protected synchronized void a(ChunkCoordIntPair chunkcoordintpair, byte[] abyte, int i) {
2019-05-06 20:45:02 +00:00
@@ -201,8 +203,9 @@ public class RegionFile implements AutoCloseable {
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
2019-05-05 17:19:34 +00:00
if (i1 >= 256) {
// Spigot start
2019-05-05 17:19:34 +00:00
- if (!ENABLE_EXTENDED_SAVE) throw new RuntimeException(String.format("Too big to save, %d > 1048576", i));
+ if (!USE_SPIGOT_OVERSIZED_METHOD && !RegionFileCache.isOverzealous()) throw new ChunkTooLargeException(chunkcoordintpair.x, chunkcoordintpair.z, l); // Paper - throw error instead
org.bukkit.Bukkit.getLogger().log(java.util.logging.Level.WARNING,"Large Chunk Detected: ({0}) Size: {1} {2}", new Object[]{chunkcoordintpair, i1, this.file});
+ if (!ENABLE_EXTENDED_SAVE) throw new RuntimeException(String.format("Too big to save, %d > 1048576", i)); // Paper - move after our check
// Spigot end
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
}
2019-05-06 20:45:02 +00:00
@@ -352,6 +355,109 @@ public class RegionFile implements AutoCloseable {
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
logger.error("Error backing up corrupt file" + file.getAbsolutePath(), e);
}
}
+
+ private final byte[] oversized = new byte[1024];
+ private int oversizedCount = 0;
+
+ private synchronized void initOversizedState() throws IOException {
+ File metaFile = getOversizedMetaFile();
+ if (metaFile.exists()) {
+ final byte[] read = java.nio.file.Files.readAllBytes(metaFile.toPath());
+ System.arraycopy(read, 0, oversized, 0, oversized.length);
+ for (byte temp : oversized) {
+ oversizedCount += temp;
+ }
+ }
+ }
+
+ private static int getChunkIndex(int x, int z) {
+ return (x & 31) + (z & 31) * 32;
+ }
+ synchronized boolean isOversized(int x, int z) {
+ return this.oversized[getChunkIndex(x, z)] == 1;
+ }
+ synchronized void setOversized(int x, int z, boolean oversized) throws IOException {
+ final int offset = getChunkIndex(x, z);
+ boolean previous = this.oversized[offset] == 1;
+ this.oversized[offset] = (byte) (oversized ? 1 : 0);
+ if (!previous && oversized) {
+ oversizedCount++;
+ } else if (!oversized && previous) {
+ oversizedCount--;
+ }
+ if (previous && !oversized) {
+ File oversizedFile = getOversizedFile(x, z);
+ if (oversizedFile.exists()) {
+ oversizedFile.delete();
+ }
+ }
+ if (oversizedCount > 0) {
+ if (previous != oversized) {
+ writeOversizedMeta();
+ }
+ } else if (previous) {
+ File oversizedMetaFile = getOversizedMetaFile();
+ if (oversizedMetaFile.exists()) {
+ oversizedMetaFile.delete();
+ }
+ }
+ }
+
+ private void writeOversizedMeta() throws IOException {
+ java.nio.file.Files.write(getOversizedMetaFile().toPath(), oversized);
+ }
+
+ private File getOversizedMetaFile() {
2019-05-05 17:19:34 +00:00
+ return new File(this.file.getParentFile(), this.file.getName().replaceAll("\\.mca$", "") + ".oversized.nbt");
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ }
+
+ private File getOversizedFile(int x, int z) {
2019-05-05 17:19:34 +00:00
+ return new File(this.file.getParentFile(), this.file.getName().replaceAll("\\.mca$", "") + "_oversized_" + x + "_" + z + ".nbt");
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ }
+
+ void writeOversizedData(int x, int z, NBTTagCompound oversizedData) throws IOException {
+ File file = getOversizedFile(x, z);
+ try (DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new DeflaterOutputStream(new java.io.FileOutputStream(file), new java.util.zip.Deflater(java.util.zip.Deflater.BEST_COMPRESSION), 32 * 1024), 32 * 1024))) {
+ NBTCompressedStreamTools.writeNBT(oversizedData, out);
+ }
+ this.setOversized(x, z, true);
+
+ }
+
+ synchronized NBTTagCompound getOversizedData(int x, int z) throws IOException {
+ File file = getOversizedFile(x, z);
+ try (DataInputStream out = new DataInputStream(new BufferedInputStream(new InflaterInputStream(new java.io.FileInputStream(file))))) {
+ return NBTCompressedStreamTools.readNBT(out);
+ }
+
+ }
+
+ private static final boolean USE_SPIGOT_OVERSIZED_METHOD = Boolean.getBoolean("Paper.useSpigotExtendedSaveMethod"); // Paper
+ static {
+ if (USE_SPIGOT_OVERSIZED_METHOD) {
+ org.bukkit.Bukkit.getLogger().log(java.util.logging.Level.SEVERE, "====================================");
+ org.bukkit.Bukkit.getLogger().log(java.util.logging.Level.SEVERE, "Using Spigot Oversized Chunk save method. Warning this will result in extremely fragmented chunks, as well as making the entire region file unable to be to used in any other software but Forge or Spigot (not usable in Vanilla or CraftBukkit). Paper's method is highly recommended.");
+ org.bukkit.Bukkit.getLogger().log(java.util.logging.Level.SEVERE, "====================================");
+ }
+ }
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ public class ChunkTooLargeException extends RuntimeException {
+ public ChunkTooLargeException(int x, int z, int sectors) {
2019-05-05 17:19:34 +00:00
+ super("Chunk " + x + "," + z + " of " + RegionFile.this.file.toString() + " is too large (" + sectors + "/255)");
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ }
+ }
+ private static class DirectByteArrayOutputStream extends ByteArrayOutputStream {
+ public DirectByteArrayOutputStream() {
+ super();
+ }
+
+ public DirectByteArrayOutputStream(int size) {
+ super(size);
+ }
+
+ public byte[] getBuffer() {
+ return this.buf;
+ }
+ }
// Paper end
class ChunkBuffer extends ByteArrayOutputStream {
2019-05-06 20:45:02 +00:00
@@ -363,8 +469,35 @@ public class RegionFile implements AutoCloseable {
2019-05-05 17:19:34 +00:00
this.b = chunkcoordintpair;
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
}
- public void close() {
2019-05-05 17:19:34 +00:00
- RegionFile.this.a(this.b, this.buf, this.count);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ public void close() throws IOException {
+ // Paper start - apply dynamic compression
+ int origLength = this.count;
+ byte[] buf = this.buf;
+ DirectByteArrayOutputStream out = compressData(buf, origLength);
+ byte[] bytes = out.getBuffer();
+ int length = out.size();
+
2019-05-05 17:19:34 +00:00
+ RegionFile.this.a(this.b, bytes, length); // Paper - change to bytes/length
}
}
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+
+ private static final byte[] compressionBuffer = new byte[1024 * 64]; // 64k fits most standard chunks input size even, ideally 1 pass through zlib
+ private static final java.util.zip.Deflater deflater = new java.util.zip.Deflater();
+ // since file IO is single threaded, no benefit to using per-region file buffers/synchronization, we can change that later if it becomes viable.
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ private static DirectByteArrayOutputStream compressData(byte[] buf, int length) throws IOException {
+ synchronized (deflater) {
+ deflater.setInput(buf, 0, length);
+ deflater.finish();
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+
+ DirectByteArrayOutputStream out = new DirectByteArrayOutputStream(length);
+ while (!deflater.finished()) {
+ out.write(compressionBuffer, 0, deflater.deflate(compressionBuffer));
+ }
+ out.close();
+ deflater.reset();
+ return out;
2019-05-05 17:19:34 +00:00
+ }
+ }
+ // Paper end
+
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
}
diff --git a/src/main/java/net/minecraft/server/RegionFileCache.java b/src/main/java/net/minecraft/server/RegionFileCache.java
2019-05-05 17:19:34 +00:00
index 1b12a16113..6893f3cd34 100644
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
--- a/src/main/java/net/minecraft/server/RegionFileCache.java
+++ b/src/main/java/net/minecraft/server/RegionFileCache.java
2019-05-05 17:19:34 +00:00
@@ -47,6 +47,7 @@ public abstract class RegionFileCache implements AutoCloseable {
// Paper start
}
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
2019-05-05 17:19:34 +00:00
+ public RegionFile getRegionFile(ChunkCoordIntPair chunkcoordintpair, boolean existingOnly) throws IOException { return this.a(chunkcoordintpair, existingOnly); } // Paper - OBFHELPER
private RegionFile a(ChunkCoordIntPair chunkcoordintpair, boolean existingOnly) throws IOException { // CraftBukkit
long i = ChunkCoordIntPair.pair(chunkcoordintpair.getRegionX(), chunkcoordintpair.getRegionZ());
RegionFile regionfile = (RegionFile) this.cache.getAndMoveToFirst(i);
@@ -79,12 +80,151 @@ public abstract class RegionFileCache implements AutoCloseable {
public synchronized boolean hasRegionFile(File file, int i, int j) {
return cache.containsKey(getRegionFileName(file, i, j));
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
}
2019-05-05 17:19:34 +00:00
+ // Paper start
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ private static void printOversizedLog(String msg, File file, int x, int z) {
+ org.apache.logging.log4j.LogManager.getLogger().fatal(msg + " (" + file.toString().replaceAll(".+[\\\\/]", "") + " - " + x + "," + z + ") Go clean it up to remove this message. /minecraft:tp " + (x<<4)+" 128 "+(z<<4) + " - DO NOT REPORT THIS TO PAPER - You may ask for help on Discord, but do not file an issue. These error messages can not be removed.");
+ }
+
+ private static final int DEFAULT_SIZE_THRESHOLD = 1024 * 8;
+ private static final int OVERZEALOUS_TOTAL_THRESHOLD = 1024 * 64;
+ private static final int OVERZEALOUS_THRESHOLD = 1024;
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ private static int SIZE_THRESHOLD = DEFAULT_SIZE_THRESHOLD;
+ private static void resetFilterThresholds() {
+ SIZE_THRESHOLD = Math.max(1024 * 4, Integer.getInteger("Paper.FilterThreshhold", DEFAULT_SIZE_THRESHOLD));
+ }
+ static {
+ resetFilterThresholds();
+ }
+
+ static boolean isOverzealous() {
+ return SIZE_THRESHOLD == OVERZEALOUS_THRESHOLD;
+ }
+
2019-05-05 17:19:34 +00:00
+ private void writeRegion(ChunkCoordIntPair chunk, NBTTagCompound nbttagcompound) throws IOException {
+ RegionFile regionfile = getRegionFile(chunk, false);
+
+ int chunkX = chunk.x;
+ int chunkZ = chunk.z;
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+
2019-05-05 17:19:34 +00:00
+ DataOutputStream out = regionfile.getWriteStream(chunk);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ try {
+ NBTCompressedStreamTools.writeNBT(nbttagcompound, out);
+ out.close();
2019-05-05 17:19:34 +00:00
+ regionfile.setOversized(chunkX, chunkZ, false);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ } catch (RegionFile.ChunkTooLargeException ignored) {
2019-05-05 17:19:34 +00:00
+ printOversizedLog("ChunkTooLarge! Someone is trying to duplicate.", regionfile.file, chunkX, chunkZ);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ // Clone as we are now modifying it, don't want to corrupt the pending save state
+ nbttagcompound = nbttagcompound.clone();
+ // Filter out TileEntities and Entities
+ NBTTagCompound oversizedData = filterChunkData(nbttagcompound);
+ //noinspection SynchronizationOnLocalVariableOrMethodParameter
+ synchronized (regionfile) {
2019-05-05 17:19:34 +00:00
+ out = regionfile.getWriteStream(chunk);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ NBTCompressedStreamTools.writeNBT(nbttagcompound, out);
+ try {
+ out.close();
+ // 2048 is below the min allowed, so it means we enter overzealous mode below
+ if (SIZE_THRESHOLD == OVERZEALOUS_THRESHOLD) {
+ resetFilterThresholds();
+ }
+ } catch (RegionFile.ChunkTooLargeException e) {
2019-05-05 17:19:34 +00:00
+ printOversizedLog("ChunkTooLarge even after reduction. Trying in overzealous mode.", regionfile.file, chunkX, chunkZ);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ // Eek, major fail. We have retry logic, so reduce threshholds and fall back
+ SIZE_THRESHOLD = OVERZEALOUS_THRESHOLD;
+ throw e;
+ }
+
2019-05-05 17:19:34 +00:00
+ regionfile.writeOversizedData(chunkX, chunkZ, oversizedData);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ }
+ }
+ }
+
+ private static NBTTagCompound filterChunkData(NBTTagCompound chunk) {
+ NBTTagCompound oversizedLevel = new NBTTagCompound();
+ NBTTagCompound level = chunk.getCompound("Level");
+ filterChunkList(level, oversizedLevel, "Entities");
+ filterChunkList(level, oversizedLevel, "TileEntities");
+ NBTTagCompound oversized = new NBTTagCompound();
+ oversized.set("Level", oversizedLevel);
+ return oversized;
+ }
+
+ private static void filterChunkList(NBTTagCompound level, NBTTagCompound extra, String key) {
+ NBTTagList list = level.getList(key, 10);
+ NBTTagList newList = extra.getList(key, 10);
+ int totalSize = 0;
2019-05-05 17:19:34 +00:00
+ for (java.util.Iterator<NBTBase> iterator = list.list.iterator(); iterator.hasNext();) {
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ NBTBase object = iterator.next();
+ int nbtSize = getNBTSize(object);
+ if (nbtSize > SIZE_THRESHOLD || (SIZE_THRESHOLD == OVERZEALOUS_THRESHOLD && totalSize > OVERZEALOUS_TOTAL_THRESHOLD)) {
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ newList.add(object);
+ iterator.remove();
+ } else {
+ totalSize += nbtSize;
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ }
+ }
+ level.set(key, list);
+ extra.set(key, newList);
+ }
+
+
2019-05-05 17:19:34 +00:00
+ private static NBTTagCompound readOversizedChunk(RegionFile regionfile, ChunkCoordIntPair chunkCoordinate) throws IOException {
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ synchronized (regionfile) {
2019-05-05 17:19:34 +00:00
+ try (DataInputStream datainputstream = regionfile.getReadStream(chunkCoordinate)) {
+ NBTTagCompound oversizedData = regionfile.getOversizedData(chunkCoordinate.x, chunkCoordinate.z);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ NBTTagCompound chunk = NBTCompressedStreamTools.readNBT(datainputstream);
+ if (oversizedData == null) {
+ return chunk;
+ }
+ NBTTagCompound oversizedLevel = oversizedData.getCompound("Level");
+ NBTTagCompound level = chunk.getCompound("Level");
+
+ mergeChunkList(level, oversizedLevel, "Entities");
+ mergeChunkList(level, oversizedLevel, "TileEntities");
+
+ chunk.set("Level", level);
+
+ return chunk;
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ throw throwable;
+ }
+ }
+ }
+
+ private static void mergeChunkList(NBTTagCompound level, NBTTagCompound oversizedLevel, String key) {
+ NBTTagList levelList = level.getList(key, 10);
+ NBTTagList oversizedList = oversizedLevel.getList(key, 10);
+
+ if (!oversizedList.isEmpty()) {
+ levelList.addAll(oversizedList);
+ level.set(key, levelList);
+ }
+ }
+
+ private static int getNBTSize(NBTBase nbtBase) {
+ DataOutputStream test = new DataOutputStream(new org.apache.commons.io.output.NullOutputStream());
+ try {
+ nbtBase.write(test);
+ return test.size();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return 0;
+ }
+ }
+
// Paper End
2019-05-05 17:19:34 +00:00
@Nullable
public NBTTagCompound read(ChunkCoordIntPair chunkcoordintpair) throws IOException {
RegionFile regionfile = this.a(chunkcoordintpair, false); // CraftBukkit
DataInputStream datainputstream = regionfile.a(chunkcoordintpair);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ // Paper start
2019-05-05 17:19:34 +00:00
+ if (regionfile.isOversized(chunkcoordintpair.x, chunkcoordintpair.z)) {
+ printOversizedLog("Loading Oversized Chunk!", regionfile.file, chunkcoordintpair.x, chunkcoordintpair.z);
+ return readOversizedChunk(regionfile, chunkcoordintpair);
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ }
+ // Paper end
2019-05-05 17:19:34 +00:00
Throwable throwable = null;
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
2019-05-05 17:19:34 +00:00
NBTTagCompound nbttagcompound;
@@ -119,29 +259,32 @@ public abstract class RegionFileCache implements AutoCloseable {
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
2019-05-05 17:19:34 +00:00
protected void write(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) throws IOException {
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
int attempts = 0; Exception laste = null; while (attempts++ < 5) { try { // Paper
2019-05-05 17:19:34 +00:00
- RegionFile regionfile = this.a(chunkcoordintpair, false); // CraftBukkit
- DataOutputStream dataoutputstream = regionfile.c(chunkcoordintpair);
- Throwable throwable = null;
-
- try {
- NBTCompressedStreamTools.a(nbttagcompound, (DataOutput) dataoutputstream);
- } catch (Throwable throwable1) {
- throwable = throwable1;
- throw throwable1;
- } finally {
- if (dataoutputstream != null) {
- if (throwable != null) {
- try {
- dataoutputstream.close();
- } catch (Throwable throwable2) {
- throwable.addSuppressed(throwable2);
- }
- } else {
- dataoutputstream.close();
- }
- }
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
-
2019-05-05 17:19:34 +00:00
- }
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ // Paper start
2019-05-05 17:19:34 +00:00
+ this.writeRegion(chunkcoordintpair, nbttagcompound);
+// RegionFile regionfile = this.a(chunkcoordintpair, false); // CraftBukkit
+// DataOutputStream dataoutputstream = regionfile.c(chunkcoordintpair);
+// Throwable throwable = null;
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+//
2019-05-05 17:19:34 +00:00
+// try {
+// NBTCompressedStreamTools.a(nbttagcompound, (DataOutput) dataoutputstream);
+// } catch (Throwable throwable1) {
+// throwable = throwable1;
+// throw throwable1;
+// } finally {
+// if (dataoutputstream != null) {
+// if (throwable != null) {
+// try {
+// dataoutputstream.close();
+// } catch (Throwable throwable2) {
+// throwable.addSuppressed(throwable2);
+// }
+// } else {
+// dataoutputstream.close();
+// }
+// }
+//
+// }
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
+ // Paper end
2019-05-05 17:19:34 +00:00
} catch (Exception ex) {
laste = ex;
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00
--
2.21.0
Allow Saving of Oversized Chunks - READ COMMIT DETAILS!!! Please test this build on a local TEST SERVER before sending to your live server! PaperMC is not responsible for any data loss to your chunks. ------------------------------------------------------------------- The Minecraft World Region File format has a hard cap of 1MB per chunk. This is due to the fact that the header of the file format only allocates a single byte for sector count, meaning a maximum of 256 sectors, at 4k per sector. This limit can be reached fairly easily with books, resulting in the chunk being unable to save to the world. Worse off, is that nothing printed when this occured, and silently performed a chunk rollback on next load. This leads to security risk with duplication and is being actively exploited. This patch catches the too large scenario, falls back and moves any large Entity or Tile Entity into a new compound, and this compound is saved into a different file. On Chunk Load, we check for oversized status, and if so, we load the extra file and merge the Entities and Tile Entities from the oversized chunk back into the level to then be loaded as normal. Once a chunk is returned back to normal size, the oversized flag will clear, and no extra data file will exist. This fix maintains compatability with all existing Anvil Region Format tools as it does not alter the save format. They will just not know about the extra entities. This fix also maintains compatability if someone switches server jars to one without this fix, as the data will remain in the oversized file. Once the server returns to a jar with this fix, the data will be restored.
2019-02-15 23:35:11 +00:00