uschindler commented on code in PR #1034:
URL: https://github.com/apache/lucene/pull/1034#discussion_r923639294


##########
lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataOutput.java:
##########
@@ -309,6 +309,24 @@ public byte[] toArrayCopy() {
     return arr;
   }
 
+  @Override
+  public void copyBytes(DataInput input, long numBytes) throws IOException {
+    assert numBytes >= 0 : "numBytes=" + numBytes;
+    int length = (int) numBytes;
+    while (length > 0) {
+      if (!currentBlock.hasRemaining()) {
+        appendBlock();
+      }
+
+      int chunk = Math.min(currentBlock.remaining(), length);
+      final int pos = currentBlock.position();
+      byte[] blockArray = currentBlock.array();

Review Comment:
   There's another problem: If the block has an array, it will always start at 
0. But if the ByteBuffer is a slice of another one, the "live" data may start 
at a lter position.
   
   To have it correct use `currentBlock.array()` and  
`currentBlock.arrayOffset()` to get the correct slice. The position must be 
added afterwards. So the following needs to be corrected to:
   
   ```java
   input.readBytes(currentBlock.array(), 
Math.addExact(currentBlock.arrayOffset(), currentBlock.position()), chunk);
   ```
   (the previous lines are obsolete)



-- 
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