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

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

lgtm, r+. One small nit though, I'd put the comment outside the method, i.e.:

{noformat}
// Since this is a rough sanity check, add some padding to maxBuffer to
// make up for extra fields, etc. (otherwise e.g. clients may be able to
// write buffers larger than we can read from disk!)
private void checkLength(int len) throws IOException {
  if (len < 0 || len > maxBuffer + 1024) {
        throw new IOException("Unreasonable length = " + len);
  }
}
{noformat}

> 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
>
>
> 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