Skip to content

Don't panic on empty core rec groups in components - #14976

Merged
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
jrandolf:empty-core-rec-groups
Oct 26, 2026
Merged

alexcrichton merged 2 commits into
bytecodealliance:mainfrom
jrandolf:empty-core-rec-groups

Conversation

@jrandolf

@jrandolf jrandolf commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

An empty core rec group in a component panics Component::new, and wasmtime compile, with the default configuration. These all validate:

  • (component (core rec)) indexes out of bounds.
  • (component (core rec) (core type (module))) unwraps an Err(()).
  • (component (core type (sub (array i8))) (core rec)) indexes out of bounds.

The component translator found each core rec group from the type at the group's first index, which an empty group doesn't have, so it looked past the end of the core types or at the next definition's type. Like the type section of core modules, it now iterates over the core types that the validator added for the section instead of over the section's rec groups, so empty rec groups have nothing to intern.

Found by fuzzing Wasmtime with components generated from the component model's binary grammar (bytecodealliance/wasm-tools#2796).

The component translator found each core rec group of a component from
the type at the group's first index, which an empty rec group doesn't
have, so `(component (core rec))` indexed out of bounds and
`(component (core rec) (core type (module)))` used the module type
instead. Empty rec groups define no types, so this skips them.
@jrandolf
jrandolf requested a review from a team as a code owner October 23, 2026 23:34
@jrandolf
jrandolf requested review from pchickey and removed request for a team October 23, 2026 23:34
Comment on lines 907 to 920

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this perhaps use a similar pattern to core modules to avoid the need to special-case here? In module_environ.rs the translation here is based on the number of types in a module, and I believe that could be done here as well by looking at the core type count within the component before/after the validator runs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This now works like module_environ.rs. It counts the core types before and after validating the section, then interns each rec group starting from its first type. An empty rec group adds no types, so it no longer needs a special case.

Like the type section in core modules, walk the core types that the
validator added for this section rather than the section's rec groups,
which handles empty rec groups without special-casing them.
@jrandolf
jrandolf requested a review from alexcrichton October 26, 2026 16:42
@alexcrichton
alexcrichton added this pull request to the merge queue Oct 26, 2026
Merged via the queue into bytecodealliance:main with commit 209d6c4 Oct 26, 2026
53 checks passed
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.

2 participants