2014-12-14 22:54:10 +01:00
From 060d619089731464443c7959814b9e2990a9bc6b Mon Sep 17 00:00:00 2001
2014-07-21 22:46:54 +02: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
2014-11-28 02:17:45 +01:00
index 61c676a..af2e2d1 100644
2014-07-21 22:46:54 +02:00
--- a/src/main/java/net/minecraft/server/JsonList.java
+++ b/src/main/java/net/minecraft/server/JsonList.java
2014-11-28 02:17:45 +01:00
@@ -149,6 +149,17 @@ public class JsonList {
2014-07-21 22:46:54 +02:00
try {
bufferedreader = Files.newReader(this.c, Charsets.UTF_8);
2014-11-28 02:17:45 +01:00
collection = (Collection) this.b.fromJson(bufferedreader, JsonList.f);
2014-07-21 22:46:54 +02:00
+ // Spigot Start
+ } catch ( java.io.FileNotFoundException ex )
+ {
2014-08-11 22:49:06 +02:00
+ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.INFO, "Unable to find file {0}, creating it.", this.c );
2014-11-28 02:17:45 +01:00
+ } catch ( com.google.gson.JsonSyntaxException ex )
2014-07-21 22:46:54 +02:00
+ {
2014-08-11 22:49:06 +02:00
+ 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 );
2014-07-21 22:46:54 +02:00
+ 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
2014-11-28 02:17:45 +01:00
index 03abfbd..bd35a0f 100644
2014-07-21 22:46:54 +02:00
--- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/src/main/java/net/minecraft/server/UserCache.java
2014-11-28 02:17:45 +01:00
@@ -160,6 +160,11 @@ public class UserCache {
break label64;
2014-07-21 22:46:54 +02:00
} catch (FileNotFoundException filenotfoundexception) {
;
+ // Spigot Start
2014-11-28 02:17:45 +01:00
+ } catch (com.google.gson.JsonSyntaxException ex) {
2014-07-25 05:21:57 +02:00
+ JsonList.a.warn( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues." );
2014-07-21 22:46:54 +02:00
+ this.g.delete();
+ // Spigot End
} finally {
IOUtils.closeQuietly(bufferedreader);
}
--
2014-11-28 02:17:45 +01:00
2.1.0
2014-07-21 22:46:54 +02:00