Skip to content

Validate map pointer/length before allocating when lifting - #14835

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
jrandolf:map-lift-validate-before-alloc
Oct 20, 2026
Merged

alexcrichton merged 1 commit into
bytecodealliance:mainfrom
jrandolf:map-lift-validate-before-alloc

Conversation

@jrandolf

@jrandolf jrandolf commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Lifting a map<K, V> into a HashMap reserved capacity for the guest-supplied length before checking that the entries actually fit in linear memory. This moves the allocation after the bounds, alignment and fuel checks, the same order lists use.

For reference, before this change a guest with a single page of memory returning (ptr = 0, len = u32::MAX) for a map<u32, u32> made the host's peak RSS jump by about 8 GiB (hashbrown initializes its control bytes) before the call failed with the bounds error. The call failed with the bounds error both before and after this change, so there's no test here; the allocation itself isn't observable from the test suite.

Closes #14810

@jrandolf
jrandolf marked this pull request as ready for review October 19, 2026 19:24
@jrandolf
jrandolf requested a review from a team as a code owner October 19, 2026 19:24
@jrandolf
jrandolf requested review from pchickey and removed request for a team October 19, 2026 19:24
@github-actions github-actions Bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Oct 19, 2026
Comment thread tests/all/component_model/func.rs Outdated
Comment thread crates/wasmtime/src/runtime/component/func/typed.rs Outdated
@alexcrichton
alexcrichton removed the request for review from pchickey October 20, 2026 16:30
Lifting a `map<K, V>` into a `HashMap` reserved capacity for the
guest-supplied length before checking that the entries actually fit in
linear memory, so a guest could make the host allocate memory
proportional to an arbitrary 32-bit length. This moves the allocation
after the bounds, alignment and fuel checks, matching how lists are
lifted.

Closes bytecodealliance#14810
@jrandolf
jrandolf force-pushed the map-lift-validate-before-alloc branch from 7426639 to 6d66184 Compare October 20, 2026 18:53
@jrandolf
jrandolf requested a review from alexcrichton October 20, 2026 19:04
@alexcrichton
alexcrichton added this pull request to the merge queue Oct 20, 2026
Merged via the queue into bytecodealliance:main with commit 1befdc5 Oct 20, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

map<K, V> allocates memory before validating the guest pointer

2 participants