Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-15424

XDR.ensureFreeSpace hangs when a corrupted bytebuffer passed into the constructor

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.5.0
    • None
    • nfs
    • None

    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.

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

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            dustinday John Doe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: