Zum Hauptinhalt springen

YamlToJsonConverterOptions

Namespace: Meshmakers.Octo.Communication.Contracts.Serialization

Limits YamlToJsonConverter enforces before and while it converts a YAML document, so that a small, caller-supplied document cannot exhaust the memory or the stack of the process that converts it.

public sealed class YamlToJsonConverterOptions

Inheritance Object → YamlToJsonConverterOptions

Remarks:

YAML aliases share one node in the document, but the conversion to JSON copies the anchored node to every use site. A few lines of nested anchors and aliases (the "billion laughs" shape) therefore expand to an unbounded JSON tree. YamlToJsonConverterOptions.MaxNodes counts the nodes as the conversion would produce them, with every alias expanded, and refuses the document before anything is expanded.

The YAML loader builds its node tree recursively and compares mapping keys by content, so a deeply nested document, or an alias chain that expands deep where it is used as a key, would overflow the stack (an uncatchable crash) before the conversion could refuse it. YamlToJsonConverterOptions.MaxDepth is therefore checked on the token stream, with every alias expanded where it stands, before the document is loaded.

The defaults are far above any real pipeline definition (the largest shipped pipelines have a few thousand YAML nodes and nest a few dozen levels deep).

Fields​

DefaultMaxNodes​

The default for YamlToJsonConverterOptions.MaxNodes.

public static long DefaultMaxNodes;

DefaultMaxDepth​

The default for YamlToJsonConverterOptions.MaxDepth.

public static int DefaultMaxDepth;

Properties​

Default​

The options with the default limits.

public static YamlToJsonConverterOptions Default { get; }

Property Value​

YamlToJsonConverterOptions

MaxNodes​

Maximum number of YAML nodes (scalars, sequences, mappings) of the document after every alias is expanded to the size of its anchored node. Must be positive.

public long MaxNodes { get; set; }

Property Value​

Int64

MaxDepth​

Maximum nesting depth of sequences and mappings, with every alias expanded where it stands. Must be positive and at most YamlToJsonConverterOptions.DefaultMaxDepth, so that the recursive YAML loader stays far away from the end of the stack.

public int MaxDepth { get; set; }

Property Value​

Int32

Constructors​

YamlToJsonConverterOptions()​

public YamlToJsonConverterOptions()

Methods​

Validate()​

internal void Validate()