fix(TypeResolver): bound resolveNodeType cluster recursion (stack-overflow DoS)#8
Conversation
…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.
|
Warning Review limit reached
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 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 infoRun configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: Files selected for processing (1)
Finishing TouchesGenerate unit tests (beta)
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Follow-up from the upstream-delta audit (PR #7's notes flagged this). The mutually-recursive type-resolution cluster in
TypeResolver.zighad no depth guard, so a cyclic semantic reference in untrusted source recursed unbounded → stack overflow → crash. Reachable via the publictypeOf()entry point.This is a sibling of the
nodeIsTypeRefcycle fixed in PR #5, but a separate family that the existingmax_alias_depthguard does not cover. Pre-existing upstream (good candidate for an upstream PR torockorager/ziglint).The cycle
resolveNodeType→resolveFieldAccess→resolveNodeType(lhs)→resolveIdentifier→findDeclarationInModule→resolveVarDeclWithName→resolveNodeType(init)→ … ∞Fix
max_resolve_depth = 64.resolveNodeTypedelegates to a newresolveNodeTypeDepth(..., 0)that returns.unknownoncedepth >= max_resolve_depth.depth: u32through every cluster member (resolveIdentifier,findDeclarationInModule,resolveVarDecl,resolveVarDeclWithName,resolveFieldAccess,resolveBuiltinCall,resolveFunctionCall,resolveCallByName,resolveMethodCall,resolveReturnType), incrementing on each recursive descent. The twonodeIsTypeRef-family entry points into the cluster start fresh at depth 0. Leaf resolvers unchanged.Mirrors the proven PR #5
max_alias_depthguard 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 overflow—const a = b.x; const b = a.y;typeOf: self-referential field access terminates without stack overflow—const a = a.x;typeOf: non-cyclic alias chain still resolves (no over-restriction)—const A = u32; const B = A; const C = B;must still resolveC → u32The 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
(281 prior + 3 new.)