You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -107,12 +108,39 @@ public record SerializableChunkData(
11
+
@@ -109,12 +_,39 @@
20
12
public static final String BLOCK_LIGHT_TAG = "BlockLight";
21
13
public static final String SKY_LIGHT_TAG = "SkyLight";
22
14
@@ -25,10 +17,10 @@ index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d
25
17
+ public static ChunkPos getChunkCoordinate(final CompoundTag chunkData) {
26
18
+ final int dataVersion = ChunkStorage.getVersion(chunkData);
27
19
+ if (dataVersion < 2842) { // Level tag is removed after this version
28
-
+ final CompoundTag levelData = chunkData.getCompound("Level");
29
-
+ return new ChunkPos(levelData.getInt("xPos"), levelData.getInt("zPos"));
20
+
+ final CompoundTag levelData = chunkData.getCompound("Level").orElse(null);
21
+
+ return new ChunkPos(levelData.getIntOr("xPos", 0), levelData.getIntOr("zPos", 0));
30
22
+ } else {
31
-
+ return new ChunkPos(chunkData.getInt("xPos"), chunkData.getInt("zPos"));
23
+
+ return new ChunkPos(chunkData.getIntOr("xPos", 0), chunkData.getIntOr("zPos", 0));
32
24
+ }
33
25
+ }
34
26
+ // Paper end - guard against serializing mismatching coordinates
@@ -40,50 +32,50 @@ index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d
40
32
+
41
33
@Nullable
42
34
public static SerializableChunkData parse(LevelHeightAccessor levelHeightAccessor, RegistryAccess registries, CompoundTag tag) {
43
-
if (!tag.contains("Status", 8)) {
35
+
if (tag.getString("Status").isEmpty()) {
44
36
return null;
45
37
} else {
46
-
- ChunkPos chunkPos = new ChunkPos(tag.getInt("xPos"), tag.getInt("zPos"));
38
+
- ChunkPos chunkPos = new ChunkPos(tag.getIntOr("xPos", 0), tag.getIntOr("zPos", 0));
47
39
+ // Paper start - Do not let the server load chunks from newer versions
48
-
+ if (tag.contains("DataVersion", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) {
49
-
+ final int dataVersion = tag.getInt("DataVersion");
40
+
+ if (tag.get("DataVersion") instanceof net.minecraft.nbt.NumericTag dataVersionTag) {
41
+
+ final int dataVersion = dataVersionTag.intValue();
50
42
+ if (!JUST_CORRUPT_IT && dataVersion > CURRENT_DATA_VERSION) {
51
43
+ new RuntimeException("Server attempted to load chunk saved with newer version of minecraft! " + dataVersion + " > " + CURRENT_DATA_VERSION).printStackTrace();
52
44
+ System.exit(1);
53
45
+ }
54
46
+ }
55
47
+ // Paper end - Do not let the server load chunks from newer versions
56
-
+ ChunkPos chunkPos = new ChunkPos(tag.getInt("xPos"), tag.getInt("zPos")); // Paper - guard against serializing mismatching coordinates; diff on change, see ChunkSerializer#getChunkCoordinate
@@ -181,7 +209,7 @@ public record SerializableChunkData(
61
-
ListTag list7 = tag.getList("sections", 10);
62
-
List<SerializableChunkData.SectionData> list8 = new ArrayList<>(list7.size());
48
+
+ ChunkPos chunkPos = new ChunkPos(tag.getIntOr("xPos", 0), tag.getIntOr("zPos", 0)); // Paper - guard against serializing mismatching coordinates; diff on change, see ChunkSerializer#getChunkCoordinate
49
+
long longOr = tag.getLongOr("LastUpdate", 0L);
50
+
long longOr1 = tag.getLongOr("InhabitedTime", 0L);
+ LOGGER.warn("Tile entity serialized in chunk {} in world '{}' positioned at {} is located outside of the chunk", this.chunkPos, level.getWorld().getName(), blockposition);
107
-
+ continue;
108
-
+ }
109
-
+ // Paper end - do not read tile entities positioned outside the chunk
110
-
protoChunk1.setBlockEntityNbt(compoundTag);
111
-
}
112
-
113
-
@@ -370,6 +412,12 @@ public record SerializableChunkData(
91
+
@@ -346,6 +_,12 @@
114
92
);
115
93
}
116
94
@@ -123,7 +101,7 @@ index d84090814956f36cacb4e1ed1e3dbad1fc8a2ab0..c7c87bc8df86ceeef3e15a8f23fc252d
123
101
public static SerializableChunkData copyOf(ServerLevel level, ChunkAccess chunk) {
124
102
if (!chunk.canBeSerialized()) {
125
103
throw new IllegalArgumentException("Chunk can't be serialized: " + chunk);
126
-
@@ -428,6 +476,12 @@ public record SerializableChunkData(
+ LOGGER.warn("Tile entity serialized in chunk " + chunkPos + " in world '" + level.getWorld().getName() + "' positioned at " + posFromTag + " is located outside of the chunk");
167
-
+ continue;
168
-
+ }
169
-
+ // Paper end - do not read tile entities positioned outside the chunk
+ .map(entry -> CompletableFuture.runAsync(() -> tryWrite(entry.getKey(), entry.getValue()), Util.DIMENSION_DATA_IO_POOL)) // Paper - Separate dimension data IO pool
+ .map(entry -> CompletableFuture.runAsync(() -> this.tryWrite(entry.getKey(), entry.getValue()), Util.DIMENSION_DATA_IO_POOL)) // Paper - Separate dimension data IO pool
0 commit comments