Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1101

bytebuffer length calculation in TBinaryProtocol writeBinary

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.7
    • Java - Library
    • None

    Description

      In TBinaryProtocol writeBinary, the length calculation appears incorrect:

      length = bin.limit() - bin.position() - bin.arrayOffset();

      This subtraction of arrayOffset can cause a negative length on a sliced buffer. For example:

      ByteBuffer b = ByteBuffer.allocate(15);
      b.put("1234567890".getBytes());

      ByteBuffer b2 = b.slice();
      b2.put("testx".getBytes());
      b2.rewind();

      So b2's length is lim-pos-offset = 5-0-10 = -5.

      I believe we just want lim-pos.

      Attachments

        Activity

          People

            bryanduxbury Bryan Duxbury
            dave111 Dave
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: