mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-02 10:36:39 +00:00
Don't trust File.length()
This commit is contained in:
parent
c62f762724
commit
ddb3b13931
1 changed files with 14 additions and 2 deletions
|
@ -114,14 +114,26 @@ public class EssentialsConf extends YamlConfiguration
|
||||||
final FileInputStream inputStream = new FileInputStream(configFile);
|
final FileInputStream inputStream = new FileInputStream(configFile);
|
||||||
try
|
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;
|
int length;
|
||||||
while ((length = inputStream.read(bytebuffer)) != -1)
|
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.put(bytebuffer, 0, length);
|
||||||
}
|
}
|
||||||
buffer.rewind();
|
buffer.rewind();
|
||||||
final CharBuffer data = CharBuffer.allocate((int)configFile.length());
|
final CharBuffer data = CharBuffer.allocate(buffer.capacity());
|
||||||
CharsetDecoder decoder = UTF8.newDecoder();
|
CharsetDecoder decoder = UTF8.newDecoder();
|
||||||
CoderResult result = decoder.decode(buffer, data, true);
|
CoderResult result = decoder.decode(buffer, data, true);
|
||||||
if (result.isError())
|
if (result.isError())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue