Skip to content

test: fix test for OOM instead of overflow#320

Merged
fitzgen merged 1 commit intofitzgen:mainfrom
overlookmotel:fix-oom-test
Apr 20, 2026
Merged

test: fix test for OOM instead of overflow#320
fitzgen merged 1 commit intofitzgen:mainfrom
overlookmotel:fix-oom-test

Conversation

@overlookmotel
Copy link
Copy Markdown
Contributor

This test appears to be outdated.

It was originally introduced in e53e771, and then modified in a221762.

The test was introduced (by the looks of it) before Bumpalo switched to bumping downwards. When bumping upwards, size = usize::MAX - p + 1 made sense as a value which would be guaranteed overflow the bump pointer.

a221762 fixed failures on nightly, but did not alter the basic logic. It changed size = (isize::MAX as usize) - p + 1.

On 64-bit platforms, this did still produce size values which would underflow in chunk_cursor_ptr.wrapping_sub(size), but more by accident than design - only because pointers don't use full 64-bit address space so p < (1 << 48). On 32-bit platforms where it's possible p could be e.g. 0x3FFF_F000, size could be small, it might not underflow, and the test could fail because alloc_layout succeeds.

Fix this test by:

  1. Making size = p + 1. bump_cursor.wrapping_sub(size) is guaranteed to wrap around with this value of size.
  2. Setting an allocation limit, so bump cannot allocate a new chunk to service the allocation request (possibly it could do successfully if p is small).

The test does assume that allocations are always made in bottom half of address space. If they're not, size will be > isize::MAX and Layout::from_size_align will return Err, so the test will fail.

That assumption was already implicit in the test - previously if p > isize::MAX, then calculating size would involve arithmetic overflow, which would panic.

This assumption is (to my knowledge) fairly safe on 64-bit platforms, where top half of address space is typically reserved for the kernel. But I'm not sure if it is safe on 32-bit platforms e.g. WASM - perhaps they may use the full 32-bit address space for heap.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates an outdated OOM regression test to reflect bumpalo’s downward-bumping behavior and avoid platform-dependent failures.

Changes:

  • Prevents the test from allocating a new backing chunk by setting an allocation limit to the currently allocated bytes.
  • Changes the “overflow” trigger size computation to p + 1 (with added rationale about address-space assumptions) to reliably cause wrap-around behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/all/tests.rs
Copy link
Copy Markdown
Owner

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Thanks

@fitzgen fitzgen merged commit 657caf8 into fitzgen:main Apr 20, 2026
12 of 13 checks passed
@overlookmotel overlookmotel deleted the fix-oom-test branch April 24, 2026 09:28
graphite-app Bot pushed a commit to oxc-project/oxc that referenced this pull request Apr 24, 2026
Fix a test for `Bump` which was failing on 32-bit in CI.

#21291 temporarily disabled the test. Turn out, there's no easy way to make this test work on 32-bit platforms, and #21510 added ample unit tests which effectively test the same thing.

So keep it disabled on 32-bit, but fix the test to make it work properly on 64-bit.

Rationale for the fix is explained in fitzgen/bumpalo#320.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants