Skip to content

GH-238: Stop TestEmptyArrowBuf writing past the end of a native allocation - #1426

Merged
jbonofre merged 1 commit into
apache:mainfrom
andygrove:fix/empty-arrowbuf-test-overflow
Nov 1, 2026
Merged

jbonofre merged 1 commit into
apache:mainfrom
andygrove:fix/empty-arrowbuf-test-overflow

Conversation

@andygrove

Copy link
Copy Markdown
Member

What's Changed

TestEmptyArrowBuf.testEmptyArrowBuf wrapped the address of Netty's empty buffer, an 8-byte native allocation, in a 1024-byte ArrowBuf and wrote 10 bytes through it. The test now backs the no-op buffer with 1024 bytes from its own allocator, so it writes only memory it owns. The assertions are unchanged.

This overrun causes the intermittent "Error occurred in starting fork" failure of arrow-memory-netty in the Windows CI job. #238 has the analysis.

Before this change, testEmptyArrowBuf fails on macOS when a malloc interposer ends 8-byte allocations at a guard page. With it, the whole memory-netty suite passes under the same interposer and normally. One green Windows run would not prove much, because the failure hit about 7% of runs.

Closes #238.

testEmptyArrowBuf wrapped the address of Netty's empty buffer in a
1024-byte ArrowBuf and wrote 10 bytes through it. That address comes
from ByteBuffer.allocateDirect(0), which is an 8-byte native
allocation, so the test wrote 2 bytes past its end.

On 64-bit Windows an 8-byte heap block has no slack, so those bytes
can land on the next block's header. The forked test JVM then exits
with a non-zero code after its tests pass, which surefire reports as
"Error occurred in starting fork" for arrow-memory-netty. This is the
most common failure of the Windows CI job.

Allocate the 1024 bytes from the test's allocator instead.
@andygrove andygrove added the bug-fix PRs that fix a big. label Oct 31, 2026
@github-actions github-actions Bot added this to the 20.0.0 milestone Oct 31, 2026

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down! That said, the purpose of the original test is now a mystery to me.

@lidavidm

lidavidm commented Nov 1, 2026

Copy link
Copy Markdown
Member

I kicked CI...

@lidavidm

lidavidm commented Nov 1, 2026

Copy link
Copy Markdown
Member

Ah, and @jbonofre wants to code freeze for release so I'll hold off merging for now

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andygrove! It looks good to me.

The fix makes sense. The old test wrapped a 1024 byte ArrowBuf around Netty's empty buffer, which is backed by only an 8 byte native allocation, so the setByte calls wrote past the end of it. That would explain the intermittent STATUS_HEAP_CORRUPTION on Windows. Backing the buffer with a real 1024 byte allocation and freeing it with try-with-resources is the right fix.

Good catch!

@jbonofre
jbonofre merged commit 221124a into apache:main Nov 1, 2026
30 of 33 checks passed
jbonofre added a commit that referenced this pull request Nov 1, 2026
…24-byte ArrowBuf (#1427)

## What's Changed

`TestNettyAllocator.testMemoryUsage` wrapped a 1024-byte `NO_OP`
`ArrowBuf` around the memory address of `PooledByteBufAllocatorL`'s
empty buffer, whose native allocation is only a few bytes. The test only
reads `memoryAddress()` today, so nothing overruns yet, but any read or
write through that buffer would run past the end of the native
allocation. That's the same problem #1426 fixes in `TestEmptyArrowBuf`.

The buffer isn't needed. The memory usage log the test waits for comes
from the status thread that the `PooledByteBufAllocatorL` constructor
starts when TRACE logging is enabled, so the test now constructs the
allocator directly and drops the `ArrowBuf`.

All `memory-netty` tests pass locally on JDK 21 with Error Prone
enabled.

Closes #238.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java][Windows] Intermittent failure to run unit test (failed: Error occurred in starting fork)

3 participants