Paper/Spigot-Server-Patches/0330-Detect-and-repair-corrupt-Region-Files.patch
Aikar 835bc39b03
Paper 1.13.1 Update
Updated Upstream (Bukkit/CraftBukkit/Spigot)

Bukkit Changes:
2dcc44dc SPIGOT-4307: Fix hacky API for banners on shields
e0fc6572 SPIGOT-4309: Add "forced" display of particles
efeeab2f Add index to README.md for easier navigation
f502bc6f Update to Minecraft 1.13.1

CraftBukkit Changes:
d0bb0a1d Fix some tests randomly failing
997d378d Fix client stall in specific teleportation scenarios
b3dc2366 SPIGOT-4307: Fix hacky API for banners on shields
2a271162 SPIGOT-4301: Fix more invalid enchants
5d0d83bb SPIGOT-4309: Add "forced" display of particles
a6772578 Add additional tests for CraftBlockData
ce1af0c3 Update to Minecraft 1.13.1

Spigot Changes:
2440e189 Rebuild patches
4ecffced Update to Minecraft 1.13.1
2018-08-26 20:51:39 -04:00

42 lines
1.8 KiB
Diff

From af0e968ff12e7722492e40654510e740fbaa2652 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 11 Aug 2018 00:49:20 -0400
Subject: [PATCH] Detect and repair corrupt Region Files
If the file has partial data written but not the full 8192 bytes,
then the server will be unable to load that region file...
I don't know why mojang only checks for 4096, when anything less than 8192 is a crash.
But to be safe, it will attempt to back up the file.
diff --git a/src/main/java/net/minecraft/server/RegionFile.java b/src/main/java/net/minecraft/server/RegionFile.java
index cba2373125..0703922332 100644
--- a/src/main/java/net/minecraft/server/RegionFile.java
+++ b/src/main/java/net/minecraft/server/RegionFile.java
@@ -41,7 +41,20 @@ public class RegionFile {
}
this.c = new RandomAccessFile(file, "rw");
- if (this.c.length() < 4096L) {
+ // Paper start - detect and fix incomplete headers
+ long length = this.c.length();
+ if (length < 8192 && length > 0) {
+ File corrupt = new File(file.getParentFile(), file.getName() + ".bak");
+ org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getLogger();
+ logger.error("Region file " + file + " was incomplete. Backing up to " + corrupt + " and repairing");
+ try {
+ java.nio.file.Files.copy(file.toPath(), corrupt.toPath());
+ } catch (IOException e) {
+ logger.error("Error backing up corrupt file", e);
+ }
+ }
+ if (length < 8192L) {
+ // Paper end
this.c.write(RegionFile.a);
this.c.write(RegionFile.a);
this.g += 8192;
--
2.18.0