2018-01-22 01:19:57 +11:00
From b541633c6f6e70ec00b0f34b1adf03dccd3a9fa6 Mon Sep 17 00:00:00 2001
2014-07-08 09:44:30 +10:00
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
2017-11-17 10:24:35 +11:00
index 1834cb5ac..0859c7eb2 100644
2014-07-08 09:44:30 +10:00
--- a/src/main/java/net/minecraft/server/JsonList.java
+++ b/src/main/java/net/minecraft/server/JsonList.java
2017-05-19 21:00:22 +10:00
@@ -172,6 +172,14 @@ public class JsonList<K, V extends JsonListEntry<K>> {
try {
bufferedreader = Files.newReader(this.c, StandardCharsets.UTF_8);
collection = (Collection) ChatDeserializer.a(this.b, (Reader) bufferedreader, (Type) JsonList.f);
+ // Spigot Start
2017-06-21 18:42:31 +10:00
+ } catch ( com.google.gson.JsonParseException ex )
2017-05-19 21:00:22 +10:00
+ {
2017-06-21 18:42:31 +10:00
+ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.WARNING, "Unable to read file " + this.c + ", backing it up to {0}.backup and creating new copy.", ex );
2017-05-19 21:00:22 +10:00
+ File backup = new File( this.c + ".backup" );
+ this.c.renameTo( backup );
+ this.c.delete();
+ // Spigot End
} finally {
IOUtils.closeQuietly(bufferedreader);
}
2014-07-08 09:44:30 +10:00
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
2017-11-17 10:24:35 +11:00
index d34768f8d..487fc11f1 100644
2014-07-08 09:44:30 +10:00
--- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/src/main/java/net/minecraft/server/UserCache.java
2017-05-14 12:00:00 +10:00
@@ -215,6 +215,11 @@ public class UserCache {
2014-07-08 09:44:30 +10:00
}
2015-05-09 21:23:26 +01:00
} catch (FileNotFoundException filenotfoundexception) {
;
+ // Spigot Start
+ } catch (com.google.gson.JsonSyntaxException ex) {
+ JsonList.a.warn( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues." );
2016-03-01 08:33:06 +11:00
+ this.h.delete();
2015-05-09 21:23:26 +01:00
+ // Spigot End
} catch (JsonParseException jsonparseexception) {
;
} finally {
2014-07-08 09:44:30 +10:00
--
2017-11-10 10:52:45 +11:00
2.14.1
2014-07-08 09:44:30 +10:00