Skip to content

wasi: accept wasm i32 pointers with high bit set - #66636

Open
guybedford wants to merge 1 commit into
nodejs:mainfrom
guybedford:wasi-int32-ptr
Open

guybedford wants to merge 1 commit into
nodejs:mainfrom
guybedford:wasi-int32-ptr

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

Fixes: #62671
Refs: #62822

Wasm i32 arguments with the high bit set are passed to JS as negative Int32 numbers, so all WASI functions taking uint32_t pointers rejected them with EINVAL. This was hit by Rspack with WASI modules using >2GB of linear memory.

This takes the general approach suggested in #62822: CheckType<uint32_t> now accepts either Uint32 or Int32, and ConvertType<uint32_t> reinterprets a negative Int32 as uint32_t, so every WASI function is fixed rather than just clock_time_get. The fast API path already received raw uint32_t and was unaffected.

The test calls clock_time_get and args_sizes_get with pointer 0x80000000 against a 1-page memory and asserts EOVERFLOW rather than EINVAL, so no large memory allocation is needed.

Wasm i32 arguments with the high bit set are passed to JS as negative
Int32 numbers, so WASI functions taking uint32_t pointers rejected
them with EINVAL. Accept Int32 in CheckType<uint32_t> and reinterpret
as uint32_t on conversion, fixing all WASI functions at once.

Fixes: nodejs#62671
Refs: nodejs#62822
Assisted-by: OpenCode
Signed-off-by: Guy Bedford <guybedford@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/wasi

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. wasi Issues and PRs related to the WebAssembly System Interface. labels Oct 10, 2026
@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.42%. Comparing base (ae5a0f4) to head (64a715b).

Files with missing lines Patch % Lines
src/node_wasi.cc 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66636      +/-   ##
==========================================
- Coverage   92.78%   90.42%   -2.36%     
==========================================
  Files         422      791     +369     
  Lines      193692   276596   +82904     
  Branches    29881    53117   +23236     
==========================================
+ Hits       179718   250120   +70402     
- Misses      13645    16869    +3224     
- Partials      329     9607    +9278     
Files with missing lines Coverage Δ
src/node_wasi.cc 63.89% <66.66%> (ø)

... and 498 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. wasi Issues and PRs related to the WebAssembly System Interface.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clock_time_get rejects valid WASI pointer arguments >= 0x80000000(2G)

3 participants