← Back to Pull requests

[Fuzzer] Handle uninhabitable types in makeCompoundRef #9282

Merged
tlively merged 6 files (116 lines) on Oct 22, 2026 19:15 UTC
View on GitHub
tlively tlively commented on Oct 20, 2026 02:27 UTC
Author

Uninhabitable heap types from the initial module are filtered out of interestingHeapTypes in setupHeapTypes, but inhabitable types in interestingHeapTypes (as well as initial module globals and functions) can still reference them. Track uninhabitableHeapTypes in TranslateToFuzzReader and check for them in makeCompoundRef, getSubType, and getSuperType so makeCompoundRef emits ref.null, local.get, or ref.as_non_null rather than infinitely recursing across non-nullable type cycles.

Diff: 116 lines (+98 / -18) across 6 files Reviewer: stevenfontanella Review duration: 3887m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.39) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 116 lines diff across 6 files
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.82 · 5 substantive comment(s)
0.82
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
87%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.285
Real PR Conversation Timeline
17 items
gemini-code-assist[bot] gemini-code-assist[bot] commented on code on Oct 20, 2026 02:29 UTC
Code Review
src/tools/fuzzing/fuzzing.cpp:1
@@ -6866,6 +6880,12 @@ bool TranslateToFuzzReader::isLoggableType(Type type) {
          loggableTypes.end();
 }
 
+bool TranslateToFuzzReader::isUninhabitable(Type type) {
+  return GCTypeUtils::isUninhabitable(type) ||
+         (type.isRef() && type.isNonNullable() &&
+          uninhabitableHeapTypes.contains(type.getHeapType()));
+}

!high

In Binaryen, Type::isNonNullable() can return true for non-reference types (such as basic types like i32 or f64), but calling Type::getHeapType() on a non-reference type will trigger an assertion failure in debug builds. Since GCTypeUtils::isUninhabitable(type) internally calls type.getHeapType() without checking type.isRef(), calling TranslateToFuzzReader::isUninhabitable on a non-reference type would result in an assertion failure.\n\nTo make this method robust and defensively guard against non-reference types, we should check type.isRef() first before calling GCTypeUtils::isUninhabitable(type) or accessing its heap type.

bool TranslateToFuzzReader::isUninhabitable(Type type) {\n  return type.isRef() &&\n         (GCTypeUtils::isUninhabitable(type) ||\n          (type.isNonNullable() &&\n           uninhabitableHeapTypes.contains(type.getHeapType())));\n}

gemini-code-assist[bot] gemini-code-assist[bot] commented on Oct 20, 2026 02:29 UTC
Reviewer

Code Review

This pull request prevents infinite recursion in makeCompoundRef during fuzzing by tracking and handling uninhabitable heap types from the initial module contents. It populates a set of uninhabitable heap types and checks it when generating compound references, falling back to null references or non-null cast escape hatches. A helper method isUninhabitable is also introduced and used during sub/supertype generation. Feedback on the changes points out a potential assertion failure in isUninhabitable when called with non-reference types, recommending a check for type.isRef() before retrieving the heap type.

tlively tlively commented on code on Oct 20, 2026 02:57 UTC
Code Review
src/tools/fuzzing/fuzzing.cpp:1
@@ -6866,6 +6880,12 @@ bool TranslateToFuzzReader::isLoggableType(Type type) {
          loggableTypes.end();
 }
 
+bool TranslateToFuzzReader::isUninhabitable(Type type) {
+  return GCTypeUtils::isUninhabitable(type) ||
+         (type.isRef() && type.isNonNullable() &&
+          uninhabitableHeapTypes.contains(type.getHeapType()));
+}

In Binaryen, Type::isNonNullable() can return true for non-reference types (such as basic types like i32 or f64)...

This is not true. Type::isNonNullable() is defined like this:

  bool isNonNullable() const { return isRef() && !(id & NullMask); }

stevenfontanella stevenfontanella commented on code on Oct 20, 2026 06:47 UTC
Code Review
src/tools/fuzzing/fuzzing.cpp:1
@@ -6866,6 +6880,12 @@ bool TranslateToFuzzReader::isLoggableType(Type type) {
          loggableTypes.end();
 }
 
+bool TranslateToFuzzReader::isUninhabitable(Type type) {
+  return GCTypeUtils::isUninhabitable(type) ||
+         (type.isRef() && type.isNonNullable() &&
+          uninhabitableHeapTypes.contains(type.getHeapType()));
+}

On that note it looks like the check for isRef here is redundant, can we remove it? Separately it'd be nice to rename isNonNullable to isNonNullableRef in another PR.

stevenfontanella stevenfontanella commented on code on Oct 20, 2026 18:30 UTC
Code Review
src/tools/fuzzing/fuzzing.cpp:1
@@ -546,6 +546,13 @@ void TranslateToFuzzReader::setupHeapTypes() {
   // Filter away uninhabitable heap types, that is, heap types that we cannot
   // construct, like a type with a non-nullable reference to itself.
   interestingHeapTypes = HeapTypeGenerator::getInhabitable(possibleHeapTypes);

We copy this into a set, should it be a set to begin with instead of a vector? I see that we add to it below, could that result in duplicates?

stevenfontanella stevenfontanella commented on code on Oct 20, 2026 18:35 UTC
Code Review
src/tools/fuzzing/fuzzing.cpp:1
@@ -6866,6 +6880,12 @@ bool TranslateToFuzzReader::isLoggableType(Type type) {
          loggableTypes.end();
 }
 
+bool TranslateToFuzzReader::isUninhabitable(Type type) {

nit: Can we rename GCTypeUtils::IsUninhabitable or make it private (I think the only remaining reference is in gc-type-utils.h itself)? Since it doesn't tell us in general if a type is uninhabitable, it just tells us whether the type is a non-nullable bottom.

stevenfontanella stevenfontanella approved these changes on Oct 20, 2026 18:38 UTC
Approved Reviewer

LGTM after comments

tlively tlively commented on code on Oct 20, 2026 20:54 UTC
Code Review
src/tools/fuzzing/fuzzing.cpp:1
@@ -546,6 +546,13 @@ void TranslateToFuzzReader::setupHeapTypes() {
   // Filter away uninhabitable heap types, that is, heap types that we cannot
   // construct, like a type with a non-nullable reference to itself.
   interestingHeapTypes = HeapTypeGenerator::getInhabitable(possibleHeapTypes);

We need it to be a vector so that "randomly" choosing an element by index based on a particular seed is deterministic. In principle we could have duplicate types if the random type generator happens to generate a type that already exists in the initial contents, but that is unlikely. It's also not a problem if it does happen; that type will just be slightly more likely to be chosen in that particular run.

tlively tlively commented on code on Oct 20, 2026 20:58 UTC
Code Review
src/tools/fuzzing/fuzzing.cpp:1
@@ -6866,6 +6880,12 @@ bool TranslateToFuzzReader::isLoggableType(Type type) {
          loggableTypes.end();
 }
 
+bool TranslateToFuzzReader::isUninhabitable(Type type) {

Renamed to isTriviallyUninhabitable.

stevenfontanella stevenfontanella approved these changes on Oct 20, 2026 20:59 UTC
Approved Reviewer

Approved these changes.

tlively tlively commented on Oct 22, 2026 05:40 UTC
Author

@stevenfontanella, it turned out that there were some other ways for uninhabitable types to slip in. PTAL at the latest changes to fix that.

stevenfontanella stevenfontanella commented on Oct 22, 2026 18:14 UTC
Contributor

The CI failure looks real, can you take a look? fuzz-uninhabitable.wast shows a diff

tlively tlively commented on Oct 22, 2026 18:36 UTC
Author

Yep, fixed now.

stevenfontanella stevenfontanella commented on code on Oct 22, 2026 18:46 UTC
Code Review
test/lit/fuzz-uninhabitable.wast:1
@@ -2,19 +2,42 @@
 ;; imported modules without infinitely recursing in makeCompoundRef.
 
 ;; RUN: wasm-opt %s -all -ttf --initial-fuzz=%s -S -o - | filecheck %s
-;; RUN: wasm-opt %s -all -ttf --fuzz-import=%s -S -o - | filecheck %s --check-prefix=IMPORT
+
+;; When importing from a module with uninhabitable types, setupHeapTypes records
+;; all uninhabitable types from the imported module in uninhabitableHeapTypes so
+;; that if an inhabitable imported type (like $2) is randomly selected into
+;; interestingHeapTypes and constructed, makeCompoundRef will emit
+;; (ref.null none) for its nullable reference to uninhabitable $0 rather than
+;; infinitely recursing. We do not check the output here because setupHeapTypes
+;; only imports a random subset of heap types and the fuzzer may not choose to
+;; construct $2 for every random input seed.

I might be missing something, can we add a seed here to make it deterministic and then check the output here?

tlively tlively commented on code on Oct 22, 2026 18:50 UTC
Code Review
test/lit/fuzz-uninhabitable.wast:1
@@ -2,19 +2,42 @@
 ;; imported modules without infinitely recursing in makeCompoundRef.
 
 ;; RUN: wasm-opt %s -all -ttf --initial-fuzz=%s -S -o - | filecheck %s
-;; RUN: wasm-opt %s -all -ttf --fuzz-import=%s -S -o - | filecheck %s --check-prefix=IMPORT
+
+;; When importing from a module with uninhabitable types, setupHeapTypes records
+;; all uninhabitable types from the imported module in uninhabitableHeapTypes so
+;; that if an inhabitable imported type (like $2) is randomly selected into
+;; interestingHeapTypes and constructed, makeCompoundRef will emit
+;; (ref.null none) for its nullable reference to uninhabitable $0 rather than
+;; infinitely recursing. We do not check the output here because setupHeapTypes
+;; only imports a random subset of heap types and the fuzzer may not choose to
+;; construct $2 for every random input seed.

Kind of. The previous version of the test did this by using the test file contents itself as the seed. The problem was that on Windows the line endings were read differently, leading to different random choices and the CI failure you saw.

Another problem is that future fuzzer changes could also change the random choices, creating an ongoing maintenance burden if this test starts failing as a result.

tlively tlively commented on Oct 22, 2026 20:19 UTC
Author

Sorry, I don't think I meant to merge this :/ Looks like I had auto-merge enabled since a couple days ago and forgot to turn it off. Happy to continue addressing any comments in a follow-up.

Assignees
tlively tlively
Labels
risk: low confidence: 87.1% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 38.8% (MEDIUM) · Higher = larger blast radius
38.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 87.1% · Lower = rushed or shallow review
87.1%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 5% · Safe to merge
5%