Return an allocation error instead of a null pointer from host allocators - #162
Open
kadircanyildirm-crypto wants to merge 1 commit into
Open
Conversation
…tors std::alloc::alloc returns null on failure, so wrapping it directly in Ok() hands callers a null pointer while the unsafe Allocator trait documents that Ok results must be valid. AllocError::AllocationFailed already exists for this, and the null-checked shape is already used elsewhere in the same files.
kadircanyildirm-crypto
force-pushed
the
fix/allocator-null-contract
branch
from
August 11, 2026 23:20
ac9edc5 to
0da4074
Compare
Contributor
Author
|
Rebased onto #163 added Re-verified on |
CoreMark Benchmark ResultsCurrent Score: 245.539 |
Code Coverage ReportCurrent Coverage: 95.30% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RustSystemAllocatorinspacewasm_utilreports a failed allocation as success:std::alloc::allocreturns NULL on failure, so the caller getsOk(null). This allocator backsPageAllocatorinspacewasi,spacewasm_stdand thecoremarkbench.PageAllocatorInner::allocpropagates a realErrwith?(src/util/paging.rs:125) but cannot see a nullOk, soPage::new(null, ..)is built and the first page is served from address zero.On
main@42781cb, forcing the failure with a page size the system cannot satisfy:With the change it reports
Err(AllocationFailed)instead.crates/spacewasm_util/tests/page_null.rscovers it.Three other allocators have the same shape and I made them consistent in the same commit, but to be clear: they are reached only through
global_allocator!, whereGlobalAllocatoralready null-checks (src/util/alloc.rs:168). I verified they returnErr(AllocationFailed)today, so for those three this is consistency, not a fix.src/is untouched.Testing
Clean checkout of
main@42781cb:cargo build --workspace --all-targets— okcargo fmt --all -- --check— cleancargo clippy --workspace --all-targets --all-features -- -D warnings— cleancargo test— all targets pass, in debug, release and withstrict-assertionscargo miri test -p spacewasm_util— clean. The new test carries#![cfg(not(miri))], since it relies on the real allocator returning NULL, which Miri does not modelOne caveat:
custom_page_sizes_integrationis OOM-killed in my container (7.6 GB;memory_maxasks for 4 GiB). It dies the same way on42781cb, so that is the environment, not the patch.Disclosure per
AI_POLICY.md. Tool: Claude Code. Type of assistance: tracing the null throughPageAllocator, building the reproduction, writing the change, the test and this description. Scope:crates/spacewasm_util/,crates/fuzzing/andtests/util/spectest.rs— the tooling (crates/*) and test exceptions; nosrc/code is touched. Level of modification: the null-checked shape is taken from the existing implementations beside it rather than invented; every command above is one I ran myself.