summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2013-05-03 01:26:51 +0200
committersnowleo <schneeleo@gmail.com>2013-05-03 01:26:51 +0200
commitd4d33043d0f4f9294f011f359d646d3ea093f3e4 (patch)
treefef6762d265b081d687377a0429e09a221b6e971
parent5906a880451f6a3be35c54194da7b02aeedf8557 (diff)
downloadEssentials-d4d33043d0f4f9294f011f359d646d3ea093f3e4.tar
Essentials-d4d33043d0f4f9294f011f359d646d3ea093f3e4.tar.gz
Essentials-d4d33043d0f4f9294f011f359d646d3ea093f3e4.tar.lz
Essentials-d4d33043d0f4f9294f011f359d646d3ea093f3e4.tar.xz
Essentials-d4d33043d0f4f9294f011f359d646d3ea093f3e4.zip
Don't trust File.length()
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsConf.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
index da2a4c6aa..bf651e6ee 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
@@ -114,14 +114,26 @@ public class EssentialsConf extends YamlConfiguration
final FileInputStream inputStream = new FileInputStream(configFile);
try
{
- final ByteBuffer buffer = ByteBuffer.allocate((int)configFile.length());
+ long startSize = configFile.length();
+ if (startSize > Integer.MAX_VALUE) {
+ throw new InvalidConfigurationException("File too big");
+ }
+ ByteBuffer buffer = ByteBuffer.allocate((int)startSize);
int length;
while ((length = inputStream.read(bytebuffer)) != -1)
{
+ if (length > buffer.remaining()) {
+ ByteBuffer resize = ByteBuffer.allocate(buffer.capacity()+length-buffer.remaining());
+ int resizePosition = buffer.position();
+ buffer.rewind();
+ resize.put(buffer);
+ resize.position(resizePosition);
+ buffer = resize;
+ }
buffer.put(bytebuffer, 0, length);
}
buffer.rewind();
- final CharBuffer data = CharBuffer.allocate((int)configFile.length());
+ final CharBuffer data = CharBuffer.allocate(buffer.capacity());
CharsetDecoder decoder = UTF8.newDecoder();
CoderResult result = decoder.decode(buffer, data, true);
if (result.isError())