3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 21:10:17 +01:00
Paper/CraftBukkit-Patches/0154-Safer-JSON-Loading.patch
Zach Brown 7b0c576798 Restructure PaperSpigot as a new set of modules
Allows us much greater control over the Spigot portion of the code
and makes us more "proper"
Credit to @Dmck2b for originally passing the idea along a while back
2014-07-21 15:46:54 -05:00

48 Zeilen
2.2 KiB
Diff

From 35a9d4a5f070fa0cc719d68c9a712819965e712b Mon Sep 17 00:00:00 2001
From: Suddenly <suddenly@suddenly.coffee>
Date: Tue, 8 Jul 2014 09:44:18 +1000
Subject: [PATCH] Safer JSON Loading
diff --git a/src/main/java/net/minecraft/server/JsonList.java b/src/main/java/net/minecraft/server/JsonList.java
index 9d1cb33..71ae29e 100644
--- a/src/main/java/net/minecraft/server/JsonList.java
+++ b/src/main/java/net/minecraft/server/JsonList.java
@@ -146,6 +146,17 @@ public class JsonList {
try {
bufferedreader = Files.newReader(this.c, Charsets.UTF_8);
collection = (Collection) this.b.fromJson(bufferedreader, f);
+ // Spigot Start
+ } catch ( java.io.FileNotFoundException ex )
+ {
+ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.INFO, "Unable to find file {0}, creating it.", this.c );
+ } catch ( net.minecraft.util.com.google.gson.JsonSyntaxException ex )
+ {
+ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.WARNING, "Unable to read file {0}, backing it up to {0}.backup and creating new copy.", this.c );
+ File backup = new File( this.c + ".backup" );
+ this.c.renameTo( backup );
+ this.c.delete();
+ // Spigot End
} finally {
IOUtils.closeQuietly(bufferedreader);
}
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
index 9f7de3f..fe42b9a 100644
--- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/src/main/java/net/minecraft/server/UserCache.java
@@ -176,6 +176,11 @@ public class UserCache {
break label81;
} catch (FileNotFoundException filenotfoundexception) {
;
+ // Spigot Start
+ } catch (net.minecraft.util.com.google.gson.JsonSyntaxException ex) {
+ org.bukkit.Bukkit.getLogger().warning( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues.");
+ this.g.delete();
+ // Spigot End
} finally {
IOUtils.closeQuietly(bufferedreader);
}
--
1.9.1