[ 
https://issues.apache.org/jira/browse/HADOOP-15424?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

John Doe updated HADOOP-15424:
------------------------------
    Description: 
When a corrupted bytebuffer passed into the constructor, i.e., the 
bytebuffer.capacity = 0, the while loop in XDR.ensureFreeSpace function hangs 
endlessly. 
This is because the loop stride (newCapacity) is always 0, making the loop 
index (newRemaining) always less than the upper bound (size).
Here is the code snippet.
{code:java}
  public XDR(ByteBuffer buf, State state) {
    this.buf = buf;
    this.state = state;
  }

  private void ensureFreeSpace(int size) {
    Preconditions.checkState(state == State.WRITING);
    if (buf.remaining() < size) {
      int newCapacity = buf.capacity() * 2;
      int newRemaining = buf.capacity() + buf.remaining();

      while (newRemaining < size) {
        newRemaining += newCapacity;
        newCapacity *= 2;
      }

      ByteBuffer newbuf = ByteBuffer.allocate(newCapacity);
      buf.flip();
      newbuf.put(buf);
      buf = newbuf;
    }
  }
{code}
 

  was:
When a corrupted bytebuffer passed into the constructor, i.e., the 
bytebuffer.capacity = 0, the while loop in XDR.ensureFreeSpace function hangs 
endlessly. 
This is because the loop stride (newCapacity) is always 0, making the loop 
index (newRemaining) always less than the upper bound (size).
Here is the code snippet.

{code:java}
  public XDR(ByteBuffer buf, State state) {
    this.buf = buf;
    this.state = state;
  }

  private void ensureFreeSpace(int size) {
    Preconditions.checkState(state == State.WRITING);
    if (buf.remaining() < size) {
      int newCapacity = buf.capacity() * 2;
      int newRemaining = buf.capacity() + buf.remaining();

      while (newRemaining < size) {
        newRemaining += newCapacity;
        newCapacity *= 2;
      }

      ByteBuffer newbuf = ByteBuffer.allocate(newCapacity);
      buf.flip();
      newbuf.put(buf);
      buf = newbuf;
    }
  }
{code}

 


> XDR.ensureFreeSpace hangs when a corrupted bytebuffer passed into the 
> constructor
> ---------------------------------------------------------------------------------
>
>                 Key: HADOOP-15424
>                 URL: https://issues.apache.org/jira/browse/HADOOP-15424
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: nfs
>    Affects Versions: 2.5.0
>            Reporter: John Doe
>            Priority: Major
>
> When a corrupted bytebuffer passed into the constructor, i.e., the 
> bytebuffer.capacity = 0, the while loop in XDR.ensureFreeSpace function hangs 
> endlessly. 
> This is because the loop stride (newCapacity) is always 0, making the loop 
> index (newRemaining) always less than the upper bound (size).
> Here is the code snippet.
> {code:java}
>   public XDR(ByteBuffer buf, State state) {
>     this.buf = buf;
>     this.state = state;
>   }
>   private void ensureFreeSpace(int size) {
>     Preconditions.checkState(state == State.WRITING);
>     if (buf.remaining() < size) {
>       int newCapacity = buf.capacity() * 2;
>       int newRemaining = buf.capacity() + buf.remaining();
>       while (newRemaining < size) {
>         newRemaining += newCapacity;
>         newCapacity *= 2;
>       }
>       ByteBuffer newbuf = ByteBuffer.allocate(newCapacity);
>       buf.flip();
>       newbuf.put(buf);
>       buf = newbuf;
>     }
>   }
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to