From 22be4d5c603f4046e2e6bea3fd7e139e3085b7b4 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 27 Dec 2021 04:11:21 -0800 Subject: [PATCH] Defensively copy chunk data in upgradeChunkTag The data provided is always from the regionfile thread, which does not copy the data out. So if two separate calls need the data, then there's going to be a problem. --- .../0258-Asynchronous-chunk-IO-and-loading.patch | 14 +++++++++++--- ...st-serializing-mismatching-chunk-coordina.patch | 4 ++-- .../server/0778-Rewrite-dataconverter-system.patch | 8 ++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/patches/server/0258-Asynchronous-chunk-IO-and-loading.patch b/patches/server/0258-Asynchronous-chunk-IO-and-loading.patch index 18d8ac3225..c219860577 100644 --- a/patches/server/0258-Asynchronous-chunk-IO-and-loading.patch +++ b/patches/server/0258-Asynchronous-chunk-IO-and-loading.patch @@ -3170,7 +3170,7 @@ index 1729af83b979e35a585c8d049b14dc23ddf23803..89de1589833dcce8028fd402aea8a3e5 CompoundTag nbttagcompound3 = new CompoundTag(); Iterator iterator1 = chunk.getHeightmaps().iterator(); diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java -index 2d1c8d5cf8ea6739d5e9df91cc16cde72917feff..d7fab2fb61dc3de14e382bac6127db956605e7ad 100644 +index 2d1c8d5cf8ea6739d5e9df91cc16cde72917feff..ba677f282f2c8a05d1bad88226655549a81679bb 100644 --- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java +++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java @@ -25,27 +25,38 @@ import net.minecraft.world.level.storage.DimensionDataStorage; @@ -3218,7 +3218,15 @@ index 2d1c8d5cf8ea6739d5e9df91cc16cde72917feff..d7fab2fb61dc3de14e382bac6127db95 if (nbt != null) { CompoundTag level = nbt.getCompound("Level"); if (level.getBoolean("TerrainPopulated")) { -@@ -80,11 +91,13 @@ public class ChunkStorage implements AutoCloseable { +@@ -63,6 +74,7 @@ public class ChunkStorage implements AutoCloseable { + + public CompoundTag upgradeChunkTag(ResourceKey resourcekey, Supplier supplier, CompoundTag nbttagcompound, Optional>> optional, ChunkPos pos, @Nullable LevelAccessor generatoraccess) throws IOException { + // CraftBukkit end ++ nbttagcompound = nbttagcompound.copy(); // Paper - defensive copy, another thread might modify this + int i = ChunkStorage.getVersion(nbttagcompound); + + // CraftBukkit start +@@ -80,11 +92,13 @@ public class ChunkStorage implements AutoCloseable { if (i < 1493) { nbttagcompound = NbtUtils.update(this.fixerUpper, DataFixTypes.CHUNK, nbttagcompound, i, 1493); if (nbttagcompound.getCompound("Level").getBoolean("hasLegacyStructureData")) { @@ -3232,7 +3240,7 @@ index 2d1c8d5cf8ea6739d5e9df91cc16cde72917feff..d7fab2fb61dc3de14e382bac6127db95 } } -@@ -129,26 +142,39 @@ public class ChunkStorage implements AutoCloseable { +@@ -129,26 +143,39 @@ public class ChunkStorage implements AutoCloseable { @Nullable public CompoundTag read(ChunkPos chunkPos) throws IOException { diff --git a/patches/server/0352-Guard-against-serializing-mismatching-chunk-coordina.patch b/patches/server/0352-Guard-against-serializing-mismatching-chunk-coordina.patch index 369500bf2c..a7467b9f93 100644 --- a/patches/server/0352-Guard-against-serializing-mismatching-chunk-coordina.patch +++ b/patches/server/0352-Guard-against-serializing-mismatching-chunk-coordina.patch @@ -38,10 +38,10 @@ index 3e631d55d30831a4063e23f9dbc7a315d11a7b68..cf86755050632b158576849b78607978 if (!Objects.equals(chunkPos, chunkcoordintpair1)) { ChunkSerializer.LOGGER.error("Chunk file at {} is in the wrong location; relocating. (Expected {}, got {})", chunkPos, chunkPos, chunkcoordintpair1); diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java -index d7fab2fb61dc3de14e382bac6127db956605e7ad..b1b1fa19cfd533d5625a462af399c5fd055629b0 100644 +index ba677f282f2c8a05d1bad88226655549a81679bb..392fd2f5919d6a8f37c9f2b0421831d6ce381e0c 100644 --- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java +++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java -@@ -147,6 +147,13 @@ public class ChunkStorage implements AutoCloseable { +@@ -148,6 +148,13 @@ public class ChunkStorage implements AutoCloseable { // Paper start - async chunk io public void write(ChunkPos chunkPos, CompoundTag nbt) throws IOException { diff --git a/patches/server/0778-Rewrite-dataconverter-system.patch b/patches/server/0778-Rewrite-dataconverter-system.patch index c2ceaf8d0f..99ba9019d7 100644 --- a/patches/server/0778-Rewrite-dataconverter-system.patch +++ b/patches/server/0778-Rewrite-dataconverter-system.patch @@ -21609,10 +21609,10 @@ index 0000000000000000000000000000000000000000..967ad1186cbc81a76a4958ea99d4eff3 + } +} diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java -index d44154ba43e06934d7889f2f20d1a27765504574..f8167882a0f11c6fff86e494800864ecf59bb8b5 100644 +index a5a45118644fc1bc8caeefa59b5f897ed590e7ae..8dfac195e7f03f8fe18ba6ee79e195efade46bea 100644 --- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java +++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkStorage.java -@@ -78,7 +78,7 @@ public class ChunkStorage implements AutoCloseable { +@@ -79,7 +79,7 @@ public class ChunkStorage implements AutoCloseable { int i = ChunkStorage.getVersion(nbttagcompound); // CraftBukkit start @@ -21621,7 +21621,7 @@ index d44154ba43e06934d7889f2f20d1a27765504574..f8167882a0f11c6fff86e494800864ec CompoundTag level = nbttagcompound.getCompound("Level"); if (level.getBoolean("TerrainPopulated") && !level.getBoolean("LightPopulated")) { ServerChunkCache cps = (generatoraccess == null) ? null : ((ServerLevel) generatoraccess).getChunkSource(); -@@ -90,7 +90,7 @@ public class ChunkStorage implements AutoCloseable { +@@ -91,7 +91,7 @@ public class ChunkStorage implements AutoCloseable { // CraftBukkit end if (i < 1493) { @@ -21630,7 +21630,7 @@ index d44154ba43e06934d7889f2f20d1a27765504574..f8167882a0f11c6fff86e494800864ec if (nbttagcompound.getCompound("Level").getBoolean("hasLegacyStructureData")) { synchronized (this.persistentDataLock) { // Paper - Async chunk loading if (this.legacyStructureHandler == null) { -@@ -112,7 +112,7 @@ public class ChunkStorage implements AutoCloseable { +@@ -113,7 +113,7 @@ public class ChunkStorage implements AutoCloseable { // Spigot end ChunkStorage.injectDatafixingContext(nbttagcompound, resourcekey, optional);