Uploaded image for project: 'ActiveMQ Artemis'
  1. ActiveMQ Artemis
  2. ARTEMIS-4340

fix artemis-journal ThreadLocalByteBufferPool.borrow zeroing

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.22.0, 2.29.0
    • 2.30.0
    • None
    • None
    • Windows 10, Linux

    Description

      Report was made (see below) about ByteUtil.uncheckedZeros throwing IndexOutOfBoundsException. Though some of ByteUtil's behaviour can perhaps be questioned, the problem ultimately starts earlier in the call tree with ThreadLocalByteBufferPool.borrow(int, boolean) from artemis-journal passing it invalid arguments. It passed in a buffer for zeroing, with its limit still set below the requested size to be zero'd, leading to the IndexOutOfBoundsException when trying to write beyond the limit.

      The reason this seemingly long-standing bug has perhaps not been hit so far is that it occurs in a less typical fallback case, where the buffer either isnt direct and able to be updated with Netty's Unsafe bits, or also doesn't have an array.

      ThreadLocalByteBufferPool should clear position+limit before zeroing the buffer.

       

      Original Description:

      =================

      In artemis-commons:

      ByteUtil.uncheckedZeros throws IndexOutOfBoundsException in the else part of the method.

      The code in the else part is looping through number of bytes specified by bytes input parameter which is often provided by buffer.capacity(), but then the code at 

      buffer.put(i + offset, zero) where buffer is of DirectByteBuffer type calls checkIndex(int i) and it throws if i is >= limit.

      But limit is not the same as capacity in a Buffer.  In our case capacity is 4096 and limit is 16 so method always throws IndexOutOfBoundsException if the else case is executed as soon as i ==16.

      This code is called when Artemis is launched and it validates/creates the various bindings files.  This causes Artemis to fail to load properly.

      Note I believe all versions of artemis-commons has this bug but I currently am testing with 2.22.0.

      Attachments

        Issue Links

          Activity

            People

              robbie Robbie Gemmell
              dahoffer David Hoffer
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 20m
                  1h 20m