{"record":{"id":"f0fe4375d0099d3a","repo":"stride3d/stride","slug":"the-length-must-be-positive","errorCode":null,"errorMessage":"The length must be positive.","messagePattern":"The length must be positive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/StringLookAheadBuffer.cs","lineNumber":81,"sourceCode":"\n        public bool EndOfInput { get { return IsOutside(currentIndex); } }\n\n        public StringLookAheadBuffer(string value)\n        {\n            this.value = value;\n        }\n\n        public char Peek(int offset)\n        {\n            int index = currentIndex + offset;\n            return IsOutside(index) ? '\\0' : value[index];\n        }\n\n        public void Skip(int length)\n        {\n            if (length < 0)\n            {\n                throw new ArgumentOutOfRangeException(\"length\", \"The length must be positive.\");\n            }\n            currentIndex += length;\n        }\n    }\n}","sourceCodeStart":63,"sourceCodeEnd":86,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/StringLookAheadBuffer.cs#L63-L86","documentation":"StringLookAheadBuffer.Skip throws ArgumentOutOfRangeException with the message 'The length must be positive.' when called with a negative length. Skip advances the read cursor by `length` characters; a negative value would move the cursor backwards, which the buffer contract forbids.","triggerScenarios":"Calling buffer.Skip(n) with n < 0 during YAML scanning — usually a scanner bug where a computed step (e.g. from an indent or length calculation) went negative.","commonSituations":"Custom or patched YAML scanner logic, miscalculated offsets when handling block scalars or indentation, or feeding malformed input through a modified parser.","solutions":["Clamp or guard the value before calling Skip: `if (n > 0) buffer.Skip(n);`","Fix the upstream length computation so it cannot go negative (e.g. Math.Max(0, len)).","If negative skip is intentional, use the buffer's rewind/backup API instead of Skip."],"exampleFix":"// before\nbuffer.Skip(indent - currentIndent); // may be negative\n// after\nvar delta = indent - currentIndent;\nif (delta > 0) buffer.Skip(delta);","handlingStrategy":"validation","validationCode":"if (length < 0)\n    throw new ArgumentException(\"Skip length must be >= 0\", nameof(length));\nbuffer.Skip(length);","typeGuard":"static bool CanSkip(int length) => length >= 0;","tryCatchPattern":"try { buffer.Skip(length); }\ncatch (ArgumentOutOfRangeException ex) { throw new YamlScannerException(\"Negative skip length computed while scanning\", ex); }","preventionTips":["Clamp computed skip amounts with Math.Max(0, n) before calling Skip.","Write scanner unit tests with indentation edge cases that can yield negative deltas.","Use the buffer's rewind API for backward movement instead of Skip."],"tags":["argument-out-of-range","yaml","parser"],"backgroundTag":"argument-out-of-range","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"}