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

deep copy of binary fields does not copy ByteBuffer characteristics (arrayOffset, position)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.4
    • 0.5
    • Java - Compiler
    • None
    • Patch Available

    Description

      Generated objects have a constructor which does a deep copy of an existing instance.

      For binary fields, the deep copy is done like that:

          if (other.isSetBinary_field()) {
            this.binary_field = ByteBuffer.wrap(new byte[other.binary_field.limit() - other.binary_field.arrayOffset()]);
            System.arraycopy(other.binary_field.array(), other.binary_field.arrayOffset(), binary_field.array(), 0, other.binary_field.limit() - other.binary_field.arrayOffset());
          }
      

      This copies the backing array of the ByteBuffer but does not set the position correctly.

      In various protocol implementations, ByteBuffer instances are serialized by considering data between position and limit, this means that an object created from another object might lead to different serialized data (and thus a different deserialized value) in case a ByteBuffer has a non default position (which can happen since ByteBuffers can be set).

      Attachments

        1. thrift-882-v2.patch
          4 kB
          Bryan Duxbury
        2. thrift-882.patch
          4 kB
          Bryan Duxbury

        Activity

          People

            bryanduxbury Bryan Duxbury
            herberts Mathias Herberts
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: