- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.4k
          HBASE-25010 assert on allocated buffer sizes before making calls to Unsafe.copyMemory
          #2380
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
  
    HBASE-25010 assert on allocated buffer sizes before making calls to Unsafe.copyMemory
  
  #2380
              Conversation
… `Unsafe.copyMemory`
| 🎊 +1 overall 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| assert (dest.capacity() - destOffset) >= length : "unsafe memory access: attempting to copy " | ||
| + length + " bytes into dest when only " + (dest.capacity() - destOffset) | ||
| + " capacity remains."; | ||
| unsafeCopy(src, srcAddress, destBase, destAddress, length); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assert are protecting calls to the method invoked by unsafeCopy: Unsafe.copyMemory. The documentation on that method makes no mention of bounds checking, and indeed I don't think it can because it accepts Object,long as parameters describing the source and destination memory addresses.
From AdoptOpenJDK:
    /**
     * Sets all bytes in a given block of memory to a copy of another
     * block.
     *
     * <p>This method determines each block's base address by means of two parameters,
     * and so it provides (in effect) a <em>double-register</em> addressing mode,
     * as discussed in {@link #getInt(Object,long)}.  When the object reference is null,
     * the offset supplies an absolute base address.
     *
     * <p>The transfers are in coherent (atomic) units of a size determined
     * by the address and length parameters.  If the effective addresses and
     * length are all even modulo 8, the transfer takes place in 'long' units.
     * If the effective addresses and length are (resp.) even modulo 4 or 2,
     * the transfer takes place in units of 'int' or 'short'.
     *
     * @since 1.7
     */
    public native void copyMemory(Object srcBase, long srcOffset,
                                  Object destBase, long destOffset,
                                  long bytes);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ndimiduk - Did you face any issue due to the lack of assert ? +1 LGTM
| 
 Not as of yet. Test runs appear clear and I haven't yet gotten this deployed into the environment where we're experiencing the crashes. I just wanted to share the patch with you experts early, in case I'm doing something obviously stupid. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
| 🎊 +1 overall 
 
 This message was automatically generated. | 
No description provided.