stride3d/stride · error · SyntaxErrorException
While scanning a %YAML directive, find extremely long…
Error message
While scanning a %YAML directive, find extremely long version number.
What it means
Scanner.ScanVersionDirectiveValue reads the %YAML directive's version numbers digit by digit and caps each component at MaxVersionNumberLength digits. A version component longer than that (dozens of digits) is nonsensical, so the scanner throws SyntaxErrorException to bound runaway input.
Solutions
- Use a valid YAML version, e.g. '%YAML 1.1' or '%YAML 1.2'.
- Remove the %YAML directive if your document does not need to declare a version.
- Check the file for duplication/corruption around the directive line.
- Catch SyntaxErrorException and report the mark to locate the bad directive.
Example fix
// before (input.yaml) %YAML 123456789012345678901234567890.1 // after (input.yaml) %YAML 1.1
Defensive patterns
Strategy: validation
Validate before calling
// C#
var m = System.Text.RegularExpressions.Regex.Match(yamlText ?? "", @"^%YAML\s+(\d+)\.(\d+)", System.Text.RegularExpressions.RegexOptions.Multiline);
if (yamlText != null && yamlText.Contains("%YAML") && (!m.Success || m.Groups[1].Value.Length > 9 || m.Groups[2].Value.Length > 9))
throw new FormatException("%YAML directive must have a short numeric major.minor version, e.g. 1.1."); Try / catch
try { deserializer.Deserialize(reader, targetType); }
catch (SyntaxErrorException ex) { throw new YamlConfigException($"Bad %YAML version at line {ex.Start.Line}", ex); } Prevention
- Only emit '%YAML 1.1' or '%YAML 1.2' from templates.
- Guard against file corruption by checksumming generated YAML.
- Reject absurd directives early in config ingestion pipelines.
When it happens
Trigger: A %YAML directive with an absurdly long version number, e.g. '%YAML 111111111111111111111.1' or a garbage line like '%YAML 00000000000000000000' whose digit run exceeds the limit.
Common situations: Corrupted or generated garbage in a directive line; concatenation bugs that duplicated digits; obfuscation/fuzzing input; accidental paste into a directives section.
Related errors
- While parsing a tag directive, did not find expected '!'.
- While scanning a %YAML directive, did not find expected…
- Invalid version dependency format. Unable to decode
- Invalid version format. Unable to decode
- The anchor ' ' already exists
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/5af2d3d7f74770de.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Scanner.cs:2281
/// %YAML 1.1 # a comment \n
/// ^
/// %YAML 1.1 # a comment \n
/// ^
/// </summary>
private int ScanVersionDirectiveNumber(Mark start)
{
int value = 0;
int length = 0;
// Repeat while the next character is digit.
while (analyzer.IsDigit())
{
// Check if the number is too long.
if (++length > MaxVersionNumberLength)
{
throw new SyntaxErrorException(start, mark, "While scanning a %YAML directive, find extremely long version number.");
}
value = value*10 + analyzer.AsDigit();
Skip();
}
// Check if the number was present.
if (length == 0)
{
throw new SyntaxErrorException(start, mark, "While scanning a %YAML directive, did not find expected version number.");
}
return value;
}
/// <summary>View on GitHub (pinned to 96fad776d2)