[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-2146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14378819#comment-14378819
 ] 

Raul Gutierrez Segales commented on ZOOKEEPER-2146:
---------------------------------------------------

Nit: we can drop the comment, the name of test is self-descriptive 

{noformat}
+    /**
+     * This test checks that
+     */
{noformat}

Instead of:

{noformat}
+        byte[] buf = new byte[4];
+        for (int i = 0; i < 4; i++) {
+            buf[i] = Byte.MAX_VALUE;
+        }
{noformat}

maybe:

{noformat}
byte[] buf = new byte[] {
   Byte.MAX_VALUE, Byte.MAX_VALUE, Byte.MAX_VALUE, Byte.MAX_VALUE};
{noformat}

Nit, instead of:

{noformat}
+            if 
(!e.getMessage().startsWith(BinaryInputArchive.UNREASONBLE_LENGTH)) {
+                Assert.fail("Not 'Unreasonable length' exception: " + e);
+            }
{noformat}

maybe, simpler:

{noformat}
Assert.assertTrue(e.getMessage().startsWith(BinaryInputArchive.UNREASONBLE_LENGTH));
{noformat}

Otherwise, lgtm!


> BinaryInputArchive readString should check length before allocating memory
> --------------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-2146
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2146
>             Project: ZooKeeper
>          Issue Type: Bug
>            Reporter: Hongchao Deng
>            Assignee: Hongchao Deng
>         Attachments: ZOOKEEPER-2146.patch, ZOOKEEPER-2146.patch, 
> ZOOKEEPER-2146.patch, ZOOKEEPER-2146.patch
>
>
> I recently observed a problem caused by malformed packets. ZK server crashed 
> because of OutOfMemoryError.
> The reason is BinaryInputArchive didn't check the length before allocating 
> memory in readString():
> {code}
>   public String readString(String tag) throws IOException {
>       int len = in.readInt();
>       if (len == -1) return null;
>       byte b[] = new byte[len];
>         ...
> {code}
> I suggest to add the same check as in readBuffer.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to