From: Marius Gavrilescu Date: Fri, 22 Mar 2013 22:03:39 +0000 (+0200) Subject: Do not go OOM on malformed poll result X-Git-Tag: 0.000_001~47 X-Git-Url: http://git.ieval.ro/?p=fonbot.git;a=commitdiff_plain;h=d5819b37350dc3f123c817fad55cdbad0c9c1c95 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. --- 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