m3l0n-sq commented on code in PR #4051:
URL: https://github.com/apache/jena/pull/4051#discussion_r3611779280


##########
jena-db/jena-dboe-base/src/main/java/org/apache/jena/dboe/base/file/BlockAccessMapped.java:
##########
@@ -149,20 +149,19 @@ private ByteBuffer getByteBuffer(long _id) {
 
         synchronized (this) {
             try {
-                // Need to put the alloc AND the slice/reset inside a sync.
+                // Need to put the alloc AND the slice inside a sync.
                 ByteBuffer segBuffer = allocSegment(seg);
-                // Now slice the buffer to get the ByteBuffer to return
-                segBuffer.position(segOff);
-                segBuffer.limit(segOff+blockSize);
-                ByteBuffer dst = segBuffer.slice();
-
-                // And then reset limit to max for segment.
-                segBuffer.limit(segBuffer.capacity());
+                // Slice from a cleared duplicate: never touches the shared
+                // segment buffer's position/limit, and does not depend on them
+                // either. The old position/limit/slice/reset sequence could
+                // leave a shrunken limit on the shared buffer if anything 
threw
+                // before the reset, poisoning every later access to a higher
+                // block in the segment ("newPosition > limit").
+                ByteBuffer dst = segBuffer.duplicate().clear().slice(segOff, 
blockSize);

Review Comment:
   You're right that `slice(segOff, blockSize)` does not modify `segBuffer`. 
Simplified this down to just using `slice(segOff, blockSize)` and removing 
`duplicate` 



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