Skip to content

Fixes potential issue in length handling in array.new (Wasm GC)#4943

Open
srberard wants to merge 1 commit into
bytecodealliance:mainfrom
srberard:fixes/gc-length-handling
Open

Fixes potential issue in length handling in array.new (Wasm GC)#4943
srberard wants to merge 1 commit into
bytecodealliance:mainfrom
srberard:fixes/gc-length-handling

Conversation

@srberard
Copy link
Copy Markdown
Contributor

Fixes #4942

Signed-off-by: Stephen Berard <stephen.berard@outlook.com>
Copilot AI review requested due to automatic review settings May 12, 2026 14:55
Copy link
Copy Markdown
Contributor

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

This PR addresses issue #4942 by hardening array.new length handling in the interpreter loader’s GC-enabled constant-expression parsing (load_init_expr) to avoid integer-overflow-driven undersized allocations that can lead to heap buffer overflows during module loading.

Changes:

  • Adjusts allocation size arithmetic for WASM_OP_ARRAY_NEW to avoid int32uint64 sign-extension overflow by casting the length through uint32.
  • Treats array.new_default’s length as uint32 when storing it into the init-expr value.

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

Comment on lines 1331 to 1335
size =
sizeof(WASMArrayNewInitValues)
+ sizeof(WASMValue) * (uint64)len_val.i32;
+ sizeof(WASMValue)
* (uint64)(uint32)len_val.i32;
if (!(array_init_values = loader_malloc(
Comment on lines 1331 to +1334
size =
sizeof(WASMArrayNewInitValues)
+ sizeof(WASMValue) * (uint64)len_val.i32;
+ sizeof(WASMValue)
* (uint64)(uint32)len_val.i32;
Copy link
Copy Markdown
Contributor

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. The signed/unsigned overflow issue appears to be resolved.
One remaining concern is that array.new still allocates based on len_val, so excessively large lengths may still cause unnecessary memory pressure in the loader. That seems worth addressing, but I’m also okay with treating it as a separate follow-up if it is outside the intended scope of this PR.

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.

Integer overflow in array.new length handling leads to heap buffer overflow in wasm-micro-runtime [BUG]

3 participants