{"record":{"id":"5af2d3d7f74770de","repo":"stride3d/stride","slug":"while-scanning-a-yaml-directive-find-extremely-long-version","errorCode":null,"errorMessage":"While scanning a %YAML directive, find extremely long version number.","messagePattern":"While scanning a %YAML directive, find extremely long version number\\.","errorType":"exception","errorClass":"SyntaxErrorException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Scanner.cs","lineNumber":2281,"sourceCode":"        ///      %YAML   1.1     # a comment \\n\n        ///              ^\n        ///      %YAML   1.1     # a comment \\n\n        ///                ^\n        /// </summary>\n        private int ScanVersionDirectiveNumber(Mark start)\n        {\n            int value = 0;\n            int length = 0;\n\n            // Repeat while the next character is digit.\n\n            while (analyzer.IsDigit())\n            {\n                // Check if the number is too long.\n\n                if (++length > MaxVersionNumberLength)\n                {\n                    throw new SyntaxErrorException(start, mark, \"While scanning a %YAML directive, find extremely long version number.\");\n                }\n\n                value = value*10 + analyzer.AsDigit();\n\n                Skip();\n            }\n\n            // Check if the number was present.\n\n            if (length == 0)\n            {\n                throw new SyntaxErrorException(start, mark, \"While scanning a %YAML directive, did not find expected version number.\");\n            }\n\n            return value;\n        }\n\n        /// <summary>","sourceCodeStart":2263,"sourceCodeEnd":2299,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Scanner.cs#L2263-L2299","documentation":"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.","triggerScenarios":"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.","commonSituations":"Corrupted or generated garbage in a directive line; concatenation bugs that duplicated digits; obfuscation/fuzzing input; accidental paste into a directives section.","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."],"exampleFix":"// before (input.yaml)\n%YAML 123456789012345678901234567890.1\n\n// after (input.yaml)\n%YAML 1.1","handlingStrategy":"validation","validationCode":"// C#\nvar m = System.Text.RegularExpressions.Regex.Match(yamlText ?? \"\", @\"^%YAML\\s+(\\d+)\\.(\\d+)\", System.Text.RegularExpressions.RegexOptions.Multiline);\nif (yamlText != null && yamlText.Contains(\"%YAML\") && (!m.Success || m.Groups[1].Value.Length > 9 || m.Groups[2].Value.Length > 9))\n    throw new FormatException(\"%YAML directive must have a short numeric major.minor version, e.g. 1.1.\");","typeGuard":null,"tryCatchPattern":"try { deserializer.Deserialize(reader, targetType); }\ncatch (SyntaxErrorException ex) { throw new YamlConfigException($\"Bad %YAML version at line {ex.Start.Line}\", ex); }","preventionTips":["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."],"tags":["yaml","directives","parsing"],"backgroundTag":"yaml-parse-error","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}