@@ -19,30 +19,30 @@ public static class YamlConverter
1919 /// Mirrors the default System.Text.Json depth limit (64) that already bounds the JSON reader path,
2020 /// protecting the recursive conversion from stack exhaustion on deeply nested documents.
2121 /// </summary>
22- public const int DefaultMaxDepth = 64 ;
22+ public const uint DefaultMaxDepth = 64 ;
2323
2424 /// <summary>
2525 /// Default maximum number of JSON nodes that may be materialized from a single YAML document.
2626 /// Guards against YAML anchor/alias expansion ("billion laughs") attacks, where a tiny document
2727 /// expands exponentially when its shared node graph is materialized into an independent JSON tree.
2828 /// </summary>
29- public const int DefaultMaxNodeCount = 5_000_000 ;
29+ public const uint DefaultMaxNodeCount = 5_000_000 ;
3030
31- private static int _maxDepth = DefaultMaxDepth ;
32- private static int _maxNodeCount = DefaultMaxNodeCount ;
31+ private static uint _maxDepth = DefaultMaxDepth ;
32+ private static uint _maxNodeCount = DefaultMaxNodeCount ;
3333
3434 /// <summary>
3535 /// Gets or sets the maximum nesting depth allowed when converting a YAML node graph into JSON nodes.
3636 /// Defaults to <see cref="DefaultMaxDepth"/>. Raise this if legitimate deeply nested documents are
3737 /// being rejected, or lower it to fail faster when only shallow documents are expected.
3838 /// </summary>
39- /// <exception cref="ArgumentOutOfRangeException">Thrown when set to a value less than 1 .</exception>
40- public static int MaxDepth
39+ /// <exception cref="ArgumentOutOfRangeException">Thrown when set to zero .</exception>
40+ public static uint MaxDepth
4141 {
4242 get => _maxDepth ;
4343 set
4444 {
45- if ( value < 1 )
45+ if ( value == 0 )
4646 {
4747 throw new ArgumentOutOfRangeException ( nameof ( value ) , "MaxDepth must be greater than zero." ) ;
4848 }
@@ -57,13 +57,13 @@ public static int MaxDepth
5757 /// ("billion laughs") attacks. Raise this if legitimate large documents are being rejected, or lower
5858 /// it to fail faster when only small documents are expected.
5959 /// </summary>
60- /// <exception cref="ArgumentOutOfRangeException">Thrown when set to a value less than 1 .</exception>
61- public static int MaxNodeCount
60+ /// <exception cref="ArgumentOutOfRangeException">Thrown when set to zero .</exception>
61+ public static uint MaxNodeCount
6262 {
6363 get => _maxNodeCount ;
6464 set
6565 {
66- if ( value < 1 )
66+ if ( value == 0 )
6767 {
6868 throw new ArgumentOutOfRangeException ( nameof ( value ) , "MaxNodeCount must be greater than zero." ) ;
6969 }
@@ -78,17 +78,17 @@ public static int MaxNodeCount
7878 /// </summary>
7979 private sealed class YamlConversionBudget
8080 {
81- private readonly int _maxDepth ;
82- private readonly int _maxNodeCount ;
83- private int _nodeCount ;
81+ private readonly uint _maxDepth ;
82+ private readonly uint _maxNodeCount ;
83+ private uint _nodeCount ;
8484
85- public YamlConversionBudget ( int maxDepth , int maxNodeCount )
85+ public YamlConversionBudget ( uint maxDepth , uint maxNodeCount )
8686 {
8787 _maxDepth = maxDepth ;
8888 _maxNodeCount = maxNodeCount ;
8989 }
9090
91- public void EnterNode ( int depth )
91+ public void EnterNode ( uint depth )
9292 {
9393 if ( depth > _maxDepth )
9494 {
@@ -133,7 +133,7 @@ public static JsonNode ToJsonNode(this YamlNode yaml)
133133 return yaml . ToJsonNode ( new YamlConversionBudget ( MaxDepth , MaxNodeCount ) , 0 ) ;
134134 }
135135
136- private static JsonNode ToJsonNode ( this YamlNode yaml , YamlConversionBudget budget , int depth )
136+ private static JsonNode ToJsonNode ( this YamlNode yaml , YamlConversionBudget budget , uint depth )
137137 {
138138 budget . EnterNode ( depth ) ;
139139 return yaml switch
@@ -176,7 +176,7 @@ public static JsonObject ToJsonObject(this YamlMappingNode yaml)
176176 return yaml . ToJsonObject ( new YamlConversionBudget ( MaxDepth , MaxNodeCount ) , 0 ) ;
177177 }
178178
179- private static JsonObject ToJsonObject ( this YamlMappingNode yaml , YamlConversionBudget budget , int depth )
179+ private static JsonObject ToJsonObject ( this YamlMappingNode yaml , YamlConversionBudget budget , uint depth )
180180 {
181181 var node = new JsonObject ( ) ;
182182 foreach ( var keyValuePair in yaml )
@@ -206,7 +206,7 @@ public static JsonArray ToJsonArray(this YamlSequenceNode yaml)
206206 return yaml . ToJsonArray ( new YamlConversionBudget ( MaxDepth , MaxNodeCount ) , 0 ) ;
207207 }
208208
209- private static JsonArray ToJsonArray ( this YamlSequenceNode yaml , YamlConversionBudget budget , int depth )
209+ private static JsonArray ToJsonArray ( this YamlSequenceNode yaml , YamlConversionBudget budget , uint depth )
210210 {
211211 var node = new JsonArray ( ) ;
212212 foreach ( var value in yaml )
0 commit comments