mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-26 00:56:39 +01:00
4104545b11
"It was from a different time before books were as jank as they are now. As time has gone on they've only proven to be worse and worse."
54 lines
3.5 KiB
Diff
54 lines
3.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
Date: Fri, 27 Dec 2019 09:42:26 -0800
|
|
Subject: [PATCH] Guard against serializing mismatching chunk coordinate
|
|
|
|
Should help if something dumb happens
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
|
index 34a026dbeafff07401187d22ef8fd537c17fc615..c131f6093c395b4d9e401d3c447e7fb13c631ecf 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
|
|
@@ -69,6 +69,13 @@ public class ChunkSerializer {
|
|
|
|
public ChunkSerializer() {}
|
|
|
|
+ // Paper start - guard against serializing mismatching coordinates
|
|
+ // TODO Note: This needs to be re-checked each update
|
|
+ public static ChunkPos getChunkCoordinate(CompoundTag chunkData) {
|
|
+ CompoundTag levelData = chunkData.getCompound("Level");
|
|
+ return new ChunkPos(levelData.getInt("xPos"), levelData.getInt("zPos"));
|
|
+ }
|
|
+ // Paper end
|
|
// Paper start
|
|
public static final class InProgressChunkHolder {
|
|
|
|
@@ -95,8 +102,8 @@ public class ChunkSerializer {
|
|
// Paper end
|
|
ChunkGenerator chunkgenerator = world.getChunkSource().getGenerator();
|
|
BiomeSource worldchunkmanager = chunkgenerator.getBiomeSource();
|
|
- CompoundTag nbttagcompound1 = nbt.getCompound("Level");
|
|
- ChunkPos chunkcoordintpair1 = new ChunkPos(nbttagcompound1.getInt("xPos"), nbttagcompound1.getInt("zPos"));
|
|
+ CompoundTag nbttagcompound1 = nbt.getCompound("Level"); // Paper - diff on change, see ChunkSerializer#getChunkCoordinate
|
|
+ ChunkPos chunkcoordintpair1 = new ChunkPos(nbttagcompound1.getInt("xPos"), nbttagcompound1.getInt("zPos")); // Paper - diff on change, see ChunkSerializer#getChunkCoordinate
|
|
|
|
if (!Objects.equals(pos, chunkcoordintpair1)) {
|
|
ChunkSerializer.LOGGER.error("Chunk file at {} is in the wrong location; relocating. (Expected {}, got {})", pos, pos, 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 6f13c7adce7d4b3d170045ea5ef2a841d34ae7b0..176610b31f66b890afe61f4de46c412382bb8d22 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
|
|
@@ -117,6 +117,13 @@ public class ChunkStorage implements AutoCloseable {
|
|
|
|
// Paper start - async chunk io
|
|
public void write(ChunkPos chunkPos, CompoundTag nbt) throws IOException {
|
|
+ // Paper start
|
|
+ if (!chunkPos.equals(ChunkSerializer.getChunkCoordinate(nbt))) {
|
|
+ String world = (this instanceof net.minecraft.server.level.ChunkMap) ? ((net.minecraft.server.level.ChunkMap)this).level.getWorld().getName() : null;
|
|
+ throw new IllegalArgumentException("Chunk coordinate and serialized data do not have matching coordinates, trying to serialize coordinate " + chunkPos.toString()
|
|
+ + " but compound says coordinate is " + ChunkSerializer.getChunkCoordinate(nbt).toString() + (world == null ? " for an unknown world" : (" for world: " + world)));
|
|
+ }
|
|
+ // Paper end
|
|
this.regionFileCache.write(chunkPos, nbt);
|
|
// Paper end - Async chunk loading
|
|
if (this.legacyStructureHandler != null) {
|