You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BufferLedger.retain can overflow the reference count to a negative value #1544
Describe the bug, including details regarding any error messages, version, and platform.
BufferLedger.retain(int) adds increment to the reference count without checking for overflow. A retain that takes the count past Integer.MAX_VALUE silently wraps it to a negative value:
try (RootAllocatorallocator = newRootAllocator()) {
ArrowBufbuf = allocator.buffer(512);
buf.getReferenceManager().retain(Integer.MAX_VALUE); // count wraps to Integer.MIN_VALUE, no error
}
// closing the allocator then reports the 512 bytes as leaked
Once the count is negative:
the ledger can never be released back to 0, so the memory leaks;
ArrowBuf.ensureAccessible() only rejects a count of exactly 0, so the buffer stays accessible;
every later retain() is rejected, as if the ledger had been released.
The retain should be rejected without changing the count, as #906 now does for a released ledger.
Two smaller follow-ups from #1543 in the same code:
In debug mode, retain records the event in the ledger history before checking the count, so a rejected retain on a released ledger shows up in the history as if it had succeeded.
testRetainOnReleasedBufferIsRejectedRepeatedly expects setInt on a released buffer to throw. That only holds when bounds checking is enabled, so the test fails with ARROW_ENABLE_UNSAFE_MEMORY_ACCESS=true.
Activity