Repository navigation
Report a block whose aliases form a cycle or expand too far as unreadable [patch] - #191
Merged
Merged
Conversation
…able [patch] YamlDotNet resolves an alias to the same object as its anchor, so an alias inside its own anchor (`a: &x [1, *x]`) produced a cyclic value, and ConvertValue copied it recursively until the stack overflowed and the host process died. Nested aliases were also expanded in full at every use, so a 350-byte block grew to a million values. ConvertValue now tracks the containers on the path it is converting and counts the values it has produced. A cycle, or more than 100,000 values, throws InvalidOperationException, which TryParseYamlObject already reports as an unreadable block, so the document is left unchanged. Fixes #159 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hnw6WDDjwQ8HvxinnWS9CF
|
This was referenced Oct 7, 2026
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.



Fixes #159
Before: an alias inside its own anchor, for example
a: &x [1, *x]ora: &x {b: *x}, madeYamlSerializer.ConvertValuerecurse until the stack overflowed. The test host died with exit code 134 andStack overflow., which no caller can catch. Nested aliases were also expanded in full at every use. A six-level, roughly 350-byte block grew to a million values, andCombineFrontmatterwrote out a 15-million-character header.After:
ConvertValuekeeps track of the containers on the path it is converting, comparing them by reference, and counts how many values it has produced. A cycle, or more thanMaxExpandedValues(100,000) values, throwsInvalidOperationException.TryParseYamlObjectalready catches that exception and reports the block as unreadable, soExtractFrontmatterreturns null andCombineFrontmatterreturns the document unchanged. An alias that is used more than once without a cycle still expands as before.ReferenceEqualityComparerisn't available on netstandard2.0/2.1, so a small private reference comparer takes its place.DeepCloneValueneeds no guard, because it only ever sees the bounded, acyclic tree thatConvertValuereturns.Tests: added
YamlAliasTests, which covers a self-referencing sequence and mapping through bothTryParseYamlObjectand the public API, the six-level alias bomb, and a non-cyclic alias used twice. With the fix reverted, the self-referencing tests crash the host (exit 134, stack overflow) and both bomb tests fail. With the fix in place, the full suite passes: 260 of 260.🤖 Generated with Claude Code
https://claude.ai/code/session_01Hnw6WDDjwQ8HvxinnWS9CF
Generated by Claude Code