Copilot commented on code in PR #10350:
URL: https://github.com/apache/ozone/pull/10350#discussion_r3401548121


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/utils/BufferUtils.java:
##########
@@ -68,6 +68,18 @@ public static ByteBuffer[] assignByteBuffers(long totalLen,
     return dataBuffers;
   }
 
+  /**
+   * Return a non-copying {@link ByteBuffer#duplicate()} of {@code src} that
+   * covers exactly {@code [position, position + length)}. Read-only-ness
+   * and direct/heap kind are inherited from {@code src}.
+   */
+  public static ByteBuffer slice(ByteBuffer src, int position, int length) {
+    final ByteBuffer slice = src.duplicate();
+    slice.position(position);
+    slice.limit(position + length);
+    return slice;
+  }

Review Comment:
   `BufferUtils.slice` is a public helper but it doesn't validate 
`position`/`length` (negative values, overflow of `position + length`, or 
ranges beyond `src.limit()`), so callers will get low-signal 
`IllegalArgumentException`s from `ByteBuffer` and potential integer overflow 
edge cases. Since this is intended as a safe range-duplicate utility, add 
explicit argument checks with clear messages.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to