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.
This commit is contained in:
Spottedleaf 2021-12-27 04:11:21 -08:00
parent 692283dbe2
commit 22be4d5c60
3 changed files with 17 additions and 9 deletions

View file

@ -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<LevelStem> resourcekey, Supplier<DimensionDataStorage> supplier, CompoundTag nbttagcompound, Optional<ResourceKey<Codec<? extends ChunkGenerator>>> 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 {