From d5819b37350dc3f123c817fad55cdbad0c9c1c95 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 23 Mar 2013 00:03:39 +0200 Subject: [PATCH] Do not go OOM on malformed poll result A bug in the server caused it to send a single space as the response to a poll. This space was stored into a fixed-size 4MB string and passed to the json.org library, which finally OOMed. The string is variable-size and the maximum size was lowered to 2MB. --- src/ro/ieval/fonbot/PollResultCallback.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ro/ieval/fonbot/PollResultCallback.java b/src/ro/ieval/fonbot/PollResultCallback.java index 2517fce..e75ffce 100644 --- a/src/ro/ieval/fonbot/PollResultCallback.java +++ b/src/ro/ieval/fonbot/PollResultCallback.java @@ -63,9 +63,9 @@ final class PollResultCallback implements ResultCallback { try{ final JSONArray array; { - final byte[] buf=new byte[4096*1024]; - inputStream.read(buf); - array=new JSONArray(new String(buf)); + final byte[] buf=new byte[2048*1024]; + final int length=inputStream.read(buf); + array=new JSONArray(new String(buf, 0, length)); } for(int i=0;i