Skip to content

fix(TypeResolver): bound resolveNodeType cluster recursion (stack-overflow DoS)#8

Merged
EugOT merged 1 commit into
mainfrom
fix/typeresolver-resolvenodetype-recursion
Jun 20, 2026
Merged

fix(TypeResolver): bound resolveNodeType cluster recursion (stack-overflow DoS)#8
EugOT merged 1 commit into
mainfrom
fix/typeresolver-resolvenodetype-recursion

Conversation

@EugOT

@EugOT EugOT commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up from the upstream-delta audit (PR #7's notes flagged this). The mutually-recursive type-resolution cluster in TypeResolver.zig had no depth guard, so a cyclic semantic reference in untrusted source recursed unbounded → stack overflow → crash. Reachable via the public typeOf() entry point.

const a = b.x;
const b = a.y;   // resolveFieldAccess <-> resolveNodeType ... → stack overflow
// also: const a = a.x;  (self-reference)

This is a sibling of the nodeIsTypeRef cycle fixed in PR #5, but a separate family that the existing max_alias_depth guard does not cover. Pre-existing upstream (good candidate for an upstream PR to rockorager/ziglint).

The cycle

resolveNodeTyperesolveFieldAccessresolveNodeType(lhs)resolveIdentifierfindDeclarationInModuleresolveVarDeclWithNameresolveNodeType(init) → … ∞

Fix

  • Added max_resolve_depth = 64.
  • resolveNodeType delegates to a new resolveNodeTypeDepth(..., 0) that returns .unknown once depth >= max_resolve_depth.
  • Threaded a depth: u32 through every cluster member (resolveIdentifier, findDeclarationInModule, resolveVarDecl, resolveVarDeclWithName, resolveFieldAccess, resolveBuiltinCall, resolveFunctionCall, resolveCallByName, resolveMethodCall, resolveReturnType), incrementing on each recursive descent. The two nodeIsTypeRef-family entry points into the cluster start fresh at depth 0. Leaf resolvers unchanged.

Mirrors the proven PR #5 max_alias_depth guard pattern exactly. No behavior change for non-cyclic input (64 ≫ any real nesting/alias chain).

Tests (TDD)

3 new tests in TypeResolver.zig:

  • typeOf: cyclic field-access aliases terminate without stack overflowconst a = b.x; const b = a.y;
  • typeOf: self-referential field access terminates without stack overflowconst a = a.x;
  • typeOf: non-cyclic alias chain still resolves (no over-restriction)const A = u32; const B = A; const C = B; must still resolve C → u32

The two cyclic tests ABRT with stack overflow before the fix (trace: resolveFieldAccess:824 ↔ resolveNodeType:645) and pass after — proving they test the right thing. The positive-control test guards against the guard being too aggressive.

Validation

zig build test --summary all
Build Summary: 7/7 steps succeeded; 284/284 tests passed
+- run test 284 pass (284 total)
+- zig fmt success
+- run exe ziglint success   # self-lint clean

(281 prior + 3 new.)

…rflow DoS)

WHY: ziglint analyzes untrusted source. The mutually-recursive type-resolution
cluster — resolveNodeType -> resolveFieldAccess/resolveIdentifier ->
findDeclarationInModule -> resolveVarDeclWithName -> resolveNodeType, plus the
@as / function-call / method-call paths — had no depth guard. A cyclic semantic
reference like `const a = b.x; const b = a.y;` (or self-referential
`const a = a.x;`) in any linted file recursed unbounded and stack-overflowed
(reproduced: ABRT via resolveFieldAccess:824 <-> resolveNodeType:645). This is a
sibling of the nodeIsTypeRef cycle fixed in PR #5, but a SEPARATE family that the
max_alias_depth guard does not cover. Found by the upstream-delta audit; the
recursion is pre-existing upstream (a candidate upstream PR), reachable via the
public typeOf() entry point.

WHAT: Added max_resolve_depth (64). resolveNodeType now delegates to a new
resolveNodeTypeDepth(..., 0) which returns .unknown once depth >= cap. Threaded a
`depth: u32` through every cluster member (resolveIdentifier,
findDeclarationInModule, resolveVarDecl, resolveVarDeclWithName, resolveFieldAccess,
resolveBuiltinCall, resolveFunctionCall, resolveCallByName, resolveMethodCall,
resolveReturnType), incrementing on each recursive descent back into the cluster.
The two external entry points in the nodeIsTypeRef family enter the cluster fresh
at depth 0. Leaf resolvers (resolvePtrType, resolveFnDecl, literals) are unchanged.

IMPACT: src/TypeResolver.zig only. No behavior change for non-cyclic input — 64 is
far beyond any real nesting/alias chain (a positive-control test confirms a valid
A->B->C alias chain still resolves to u32). Eliminates a remotely-triggerable
linter crash on adversarial source.

VALIDATION: TDD — the two cyclic tests (cyclic field-access pair + self-reference)
ABRT with stack overflow before the fix and pass after; a non-cyclic alias-chain
test guards against over-restriction. `zig build test --summary all` => 7/7 steps,
284/284 tests pass (281 prior + 3 new), zig fmt clean, self-lint clean.
Copilot AI review requested due to automatic review settings June 20, 2026 12:32
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@EugOT, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 24 minutes and 39 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

Review info
Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: c04e6151-bb5c-4b1e-8583-72cdfd436c83

Commits

Reviewing files that changed from the base of the PR and between 1704982 and f21c76b.

Files selected for processing (1)
  • src/TypeResolver.zig
Finishing Touches
Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/typeresolver-resolvenodetype-recursion

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@EugOT

EugOT commented Jun 20, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@EugOT EugOT merged commit 299316f into main Jun 20, 2026
6 of 7 checks passed
@EugOT EugOT deleted the fix/typeresolver-resolvenodetype-recursion branch June 20, 2026 12:36
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