Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-26197

Fix some obvious bugs in MultiByteBuff.put

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.0-alpha-1, 2.4.5
    • 2.5.0, 3.0.0-alpha-2, 2.3.7, 2.4.7
    • None
    • None
    • Reviewed

    Description

      MultiByteBuff.put(int destOffset, ByteBuff src, int srcOffset, int length) has some obvious bugs:

      • It seems mix up items in src MutiByteBuff and items in the dest MultiByteBuff , just as line 749 and line 754 illustrated. The logic is only right when src ByteBuff is also a MultiByteBuff and byte size of every ByteBuffer in src.items has exactly the same size as every ByteBuffer in the dest.items,but looking the usage of this method in the hbase project, obviously the assumption is not right.
        746     public MultiByteBuff put(int offset, ByteBuff src, int srcOffset, int length) {
        747         checkRefCount();
        748         int destItemIndex = getItemIndex(offset);
        749         int srcItemIndex = getItemIndex(srcOffset);
        750         ByteBuffer destItem = this.items[destItemIndex];
        751         offset = offset - this.itemBeginPos[destItemIndex];
        752
        753        ByteBuffer srcItem = getItemByteBuffer(src, srcItemIndex);
        754        srcOffset = srcOffset - this.itemBeginPos[srcItemIndex];
                    ...
        
      • If src is SingleByteBuff and its remaining space is fewer than length,when remaining space is exhausted, this MultiByteBuff.put method would not throw any exception and continue to put src ByteBuff once again from position 0 because following MultiByteBuff.getItemByteBuffer ignores index paramter for SingleByteBuff . Obviously, this behavior is much strange and unexpected.
               private static ByteBuffer getItemByteBuffer(ByteBuff buf, int index) {
                     return (buf instanceof SingleByteBuff) ? buf.nioByteBuffers()[0]
                           : ((MultiByteBuff) buf).items[index];
                }
           

      Why seems tests is OK with too much bugs? Because in normal cases, we just use SingleByteBuff not MultiByteBuff.

      Attachments

        Issue Links

          Activity

            People

              comnetwork chenglei
              comnetwork chenglei
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: