From c93d1f53beb291f8fc70f11cfe50a6d841d7675b Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 11 Aug 2018 00:55:42 -0400 Subject: [PATCH] Detect and repair corrupt Region Files - Closes #1317 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. --- ...tect-and-repair-corrupt-Region-Files.patch | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Spigot-Server-Patches/0334-Detect-and-repair-corrupt-Region-Files.patch diff --git a/Spigot-Server-Patches/0334-Detect-and-repair-corrupt-Region-Files.patch b/Spigot-Server-Patches/0334-Detect-and-repair-corrupt-Region-Files.patch new file mode 100644 index 000000000..1c3310255 --- /dev/null +++ b/Spigot-Server-Patches/0334-Detect-and-repair-corrupt-Region-Files.patch @@ -0,0 +1,41 @@ +From 791918c4893844b0cb19a6cc9a4a717bd83a1509 Mon Sep 17 00:00:00 2001 +From: Aikar +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 cba23731..07039223 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 +