Skip to content

A deeply nested value set literal overflows the stack and kills the process #248

Closed

Description

@CaffeinatedCoder

Problem

A value set literal made of deeply nested braces overflows the stack, and .NET cannot catch a stack overflow, so the process dies. Found by the final pre-release analysis on origin/main add665c.

  • Int32Set.TryParse(new string('{', 50000) + new string('}', 50000), null, out _) crashes instead of returning false. "{"*N + "1" + "}"*N crashes too: the walk recurses before it reaches the element.
  • Remotely triggerable. A Release Kestrel app with a minimal API taking [FromHeader] Int32Set answered 200 at depth 9,000 (an 18 KB header) and died with exit code 134 at depth 12,000 (24 KB, under Kestrel's default 32 KB header limit). Log: Stack overflow. at SetFormat.<IsNestOfEmptyArrays>g__Shape….
  • Every set type, on every path that reaches SetFormat.Parse: Parse/TryParse, the TypeConverter (MVC, configuration binding), minimal-API binding, and the EF JSON-column reader (by trace). Decorated literals ([1:1]=…) and multirange literals are safe; they were measured at 200k depth.
  • Where: src/CodoMetis.ValueRanges/Internals/SetFormat.cs, IsNestOfEmptyArrays → the recursive local Shape. It came in with Value set literals refuse array_in's dimension decoration ([1:1]={…}) and {{}} #128 (Depth, cdba442), and fix: refuse a ragged nest of empty arrays in value set literals #240 kept the recursion. 9.1.0 does not have this code, so nothing that shipped is affected.
  • Measured on macOS: the main thread overflows between 10k and 50k levels, a thread-pool thread between 6k and 8k. Linux thread stacks were not measured.

Change

Make the walk iterative, or stop at depth 6, which is PostgreSQL's MAXDIM. The cap also fixes #250. Check every other recursive walk over untrusted literal text in src/ (range, multirange, element quoting) for the same shape.

Done when

Int32Set.TryParse of 100,000 nested braces returns false, and the same input through the TypeConverter and JSON is refused. A test over every discovered set type holds it in-process: it must not crash the test host, so bound the depth the test feeds. The fix commit carries Found-By: and Defect-Class: trailers.

Activity

  1. added this to the 10.0.0 milestone on Oct 19, 2026
  2. added
    bug
    area/value-sets
    area/literals
    package/core
    severity/critical
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/literalsarea/value-setsbugpackage/coreseverity/critical

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions