Do not go OOM on malformed poll result
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 22 Mar 2013 22:03:39 +0000 (00:03 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 22 Mar 2013 22:03:39 +0000 (00:03 +0200)
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

index 2517fce29f8e65d04f8cb3963ff05612af770416..e75ffce2f3548f4c541a83e17790c605cd8453b0 100644 (file)
@@ -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<array.length();i++){
This page took 0.010953 seconds and 4 git commands to generate.