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 may not always start at 0. If the ByteBuffer is a slice of another one, the "live" data may start at a later offset. position != arrayOffset, that are 2 different coordinates. This may be important if the input is a memory mapped index input or similar. 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org