Skip to content

Commit

Permalink
LinuxFile reused scratch buffers ensuring size was suaable. But the l…
Browse files Browse the repository at this point in the history
…imit value cannot be modified so later usage failed as an intended overwrite
  • Loading branch information
taartspi committed Mar 1, 2024
1 parent ca45f76 commit ed208f2
Showing 1 changed file with 17 additions and 13 deletions.
Expand Up @@ -211,34 +211,38 @@ protected static int getWordSize() {
protected synchronized IntBuffer getOffsetsBuffer(int size) {
final int byteSize = size * 4;
IntBuffer buf = localOffsetsBuffer.get();

if (buf != null) {
// always reallocate buffer to ensure correct limits
localOffsetsBuffer.remove();
buf = localOffsetsBuffer.get();
}
if (byteSize > localBufferSize)
throw new ScratchBufferOverrun();

if (buf == null) {
ByteBuffer bb = ByteBuffer.allocateDirect(localBufferSize);
ByteBuffer bb = ByteBuffer.allocateDirect(localBufferSize);

//keep native order, set before cast to IntBuffer
bb.order(ByteOrder.nativeOrder());
//keep native order, set before cast to IntBuffer
bb.order(ByteOrder.nativeOrder());

buf = bb.asIntBuffer();
localOffsetsBuffer.set(buf);
}
buf = bb.asIntBuffer();
localOffsetsBuffer.set(buf);

return buf;
}


protected synchronized ByteBuffer getDataBuffer(int size) {
ByteBuffer buf = localDataBuffer.get();

if (buf != null) {
// always reallocate buffer to ensure correct limits
localDataBuffer.remove();
buf = localDataBuffer.get();
}
if (size > localBufferSize)
throw new ScratchBufferOverrun();

if (buf == null) {
buf = ByteBuffer.allocateDirect(size);
localDataBuffer.set(buf);
}
buf = ByteBuffer.allocateDirect(size);
localDataBuffer.set(buf);

return buf;
}
Expand Down

0 comments on commit ed208f2

Please sign in to comment.