diff options
author | Wesley Wolfe <weswolf@aol.com> | 2013-10-06 22:37:44 -0500 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2013-10-06 22:37:44 -0500 |
commit | ca5e0c6db0ee1b104158b973d9095d95d80de835 (patch) | |
tree | 1972948f49e50b8af80020e19d7db8c3fd1b538a /src | |
parent | cfa5490a58b9ab857317b75abecc9c6e5a07bc1a (diff) | |
download | craftbukkit-ca5e0c6db0ee1b104158b973d9095d95d80de835.tar craftbukkit-ca5e0c6db0ee1b104158b973d9095d95d80de835.tar.gz craftbukkit-ca5e0c6db0ee1b104158b973d9095d95d80de835.tar.lz craftbukkit-ca5e0c6db0ee1b104158b973d9095d95d80de835.tar.xz craftbukkit-ca5e0c6db0ee1b104158b973d9095d95d80de835.zip |
Add exception-resilience to reading UUID. Fixes BUKKIT-4833
When a "uid.dat" file is corrupt (empty or <16 bytes), WorldNBTStorage
will silently fail to read and return null. Non-null behavior is
expected everywhere that this value is used.
This change will force a random UUID when the previous UUID cannot be
read, and getUUID to no longer silently ignore read/write exceptions.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/net/minecraft/server/WorldNBTStorage.java | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/src/main/java/net/minecraft/server/WorldNBTStorage.java b/src/main/java/net/minecraft/server/WorldNBTStorage.java index e9134b32..321f65b9 100644 --- a/src/main/java/net/minecraft/server/WorldNBTStorage.java +++ b/src/main/java/net/minecraft/server/WorldNBTStorage.java @@ -8,7 +8,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.logging.Logger; // CraftBukkit start import java.util.UUID; @@ -247,25 +246,42 @@ public class WorldNBTStorage implements IDataManager, IPlayerFileData { // CraftBukkit start public UUID getUUID() { if (uuid != null) return uuid; - try { - File file1 = new File(this.baseDir, "uid.dat"); - if (!file1.exists()) { - DataOutputStream dos = new DataOutputStream(new FileOutputStream(file1)); - uuid = UUID.randomUUID(); - dos.writeLong(uuid.getMostSignificantBits()); - dos.writeLong(uuid.getLeastSignificantBits()); - dos.close(); - } - else { - DataInputStream dis = new DataInputStream(new FileInputStream(file1)); - uuid = new UUID(dis.readLong(), dis.readLong()); - dis.close(); + File file1 = new File(this.baseDir, "uid.dat"); + if (file1.exists()) { + DataInputStream dis = null; + try { + dis = new DataInputStream(new FileInputStream(file1)); + return uuid = new UUID(dis.readLong(), dis.readLong()); + } catch (IOException ex) { + MinecraftServer.getServer().getLogger().severe("Failed to read " + file1 + ", generating new random UUID", ex); + } finally { + if (dis != null) { + try { + dis.close(); + } catch (IOException ex) { + // NOOP + } + } } - return uuid; } - catch (IOException ex) { - return null; + uuid = UUID.randomUUID(); + DataOutputStream dos = null; + try { + dos = new DataOutputStream(new FileOutputStream(file1)); + dos.writeLong(uuid.getMostSignificantBits()); + dos.writeLong(uuid.getLeastSignificantBits()); + } catch (IOException ex) { + MinecraftServer.getServer().getLogger().severe("Failed to write " + file1, ex); + } finally { + if (dos != null) { + try { + dos.close(); + } catch (IOException ex) { + // NOOP + } + } } + return uuid; } public File getPlayerDir() { |