Repository navigation
fix: cap the nested-empty array walk at PostgreSQL's six dimensions - #266
Merged
Merged
Conversation
SetFormat.IsNestOfEmptyArrays (#128, #240) recursed once per brace with no limit. A literal of a few thousand nested braces overflowed the stack, which .NET cannot catch, so Int32Set.TryParse killed the process instead of returning false, and a 24 KB [FromHeader] Int32Set header killed a Kestrel app (#248, critical). And a nest of empty arrays deeper than six levels read as {}, though PostgreSQL 16, 17 and 18 all refuse it: "number of array dimensions exceeds the maximum allowed (6)" (#250). The walk now stops at MaxDimensions, PostgreSQL's MAXDIM: a seventh level is not a nest, the literal falls to the element parser, which refuses a nested brace at once, and the recursion never exceeds six frames. No other walk in src/ recurses over literal text (range, multirange and element quoting are loops; ValueSetSqlGuard walks EF's SQL tree). Measured: six levels read as {} on 17 and 18, seven are refused everywhere. By hand: 100,000 nested braces, empty or around an element, return false through TryParse and throw FormatException through the TypeConverter, even on a 256 KB thread. NestedLiteralDepthContractTests (new oracle) feeds every set type seven-level, twenty-level and thousand-level literals through Parse, TryParse and the TypeConverter: depths the old recursion survives, so it fails rather than crashes the host. SetDimensionDecorationTests, the nested-empty version test and the corpus gain six-level (read on 17+) and seven-level (refused) rows. With the cap removed: 2 unit rows, the contract test and 29 live tests fail. Seed nested-empty-walk-uncapped.patch is CAUGHT by all three oracles; ragged-nest-read-as-empty.patch is re-planted on the new walk. Closes #248 Closes #250 Found-By: CA Defect-Class: LIT Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #248
Closes #250
Problem
SetFormat.IsNestOfEmptyArrays(#128, #240) recursed once per brace, with no limit.Int32Set.TryParsekilled the process instead of returningfalse, and a 24 KB[FromHeader] Int32Setheader killed a Kestrel app.{}. PostgreSQL 16, 17 and 18 all reject it ("number of array dimensions exceeds the maximum allowed (6)").Both came in with 10.0.0; 9.1.0 doesn't have this code.
Change
MaxDimensions(6), PostgreSQL's MAXDIM. A seventh level is not a nest, so the literal falls through to the element parser, which rejects a nested brace immediately. The recursion never goes deeper than six frames.src/recurses over literal text. The range, multirange and element-quoting parsers are loops. The other self-calls are overloads orValueSetSqlGuard's walk of EF's SQL tree.pg_input_is_valid(…, 'int4[]')): six levels of empties read as{}on 17 and 18 and are rejected by 16. Seven levels are rejected everywhere, with or without an element.docs/value-sets.md: the nested-empty bullet now says ragged nests and nests deeper than six levels fail.Tests
NestedLiteralDepthContractTests(conventions). Every discovered set type gets 7-, 20- and 1,000-level literals, empty and around an element, throughParse,TryParse(string and span) and the TypeConverter. The old recursion survives these depths, so a revert makes the test fail rather than crash the host.SetDimensionDecorationTests,NestedEmptyArrays_…and the corpus probe: six levels are read on 17+, seven are rejected.nested-empty-walk-uncapped.patch: CAUGHT by all three oracles.ragged-nest-read-as-empty.patchno longer applied and is re-planted on the new walk; still CAUGHT.falsefromTryParseforInt32SetandStringSet, even on a 256 KB thread, andFormatExceptionfrom the TypeConverter.No changelog entry: this never shipped. The 10.0.0 line for #128 still says what reads.
🤖 Generated with Claude Code