{"record":{"id":"14aa17e24fd1db6c","repo":"stride3d/stride","slug":"invalid-offset-offset","errorCode":null,"errorMessage":"Invalid offset {offset}","messagePattern":"Invalid offset (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Collections/Dequeue.cs","lineNumber":421,"sourceCode":"        if (index < 0 || index >= sourceLength)\n        {\n            throw new ArgumentOutOfRangeException(nameof(index), \"Invalid existing index \" + index + \" for source length \" + sourceLength);\n        }\n    }\n\n    /// <summary>\n    /// Checks the <paramref name=\"offset\"/> and <paramref name=\"count\"/> arguments for validity when applied to a source of a given length. Allows 0-element ranges, including a 0-element range at the end of the source.\n    /// </summary>\n    /// <param name=\"sourceLength\">The length of the source. This parameter is not checked for validity.</param>\n    /// <param name=\"offset\">The index into source at which the range begins.</param>\n    /// <param name=\"count\">The number of elements in the range.</param>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Either <paramref name=\"offset\"/> or <paramref name=\"count\"/> is less than 0.</exception>\n    /// <exception cref=\"ArgumentException\">The range [offset, offset + count) is not within the range [0, sourceLength).</exception>\n    private static void CheckRangeArguments(int sourceLength, int offset, int count)\n    {\n        if (offset < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(offset), \"Invalid offset \" + offset);\n        }\n\n        if (count < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(count), \"Invalid count \" + count);\n        }\n\n        if (sourceLength - offset < count)\n        {\n            throw new ArgumentException(\"Invalid offset (\" + offset + \") or count + (\" + count + \") for source length \" + sourceLength);\n        }\n    }\n\n    #endregion\n\n    /// <summary>\n    /// Gets a value indicating whether this instance is empty.\n    /// </summary>","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Collections/Dequeue.cs#L403-L439","documentation":"Thrown by CheckRangeArguments when the offset of a range operation is negative. The deque requires offset >= 0 for CopyTo and RemoveRange; a negative offset cannot address any part of the source. Raised as ArgumentOutOfRangeException naming 'offset'.","triggerScenarios":"Calling range-taking members (CopyTo / RemoveRange overloads that go through CheckRangeArguments) with a negative offset, e.g. RemoveRange(-1, 5).","commonSituations":"Computing offset as (startIndex - count) which underflows below zero; integer arithmetic on sizes that went negative; passing an unchecked user-supplied offset.","solutions":["Validate offset >= 0 before the call, throwing or clamping as appropriate","Re-check the arithmetic that produces the offset (subtraction may underflow)","If clamping, decide explicitly whether a negative offset should mean 0 or an error rather than letting it propagate"],"exampleFix":"// before\ndeque.RemoveRange(start - count, count); // start < count => negative offset\n// after\nint offset = Math.Max(0, start - count);\ndeque.RemoveRange(offset, count);","handlingStrategy":"validation","validationCode":"if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset));\ndeque.RemoveRange(offset, count);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate offset >= 0 as a precondition in wrapper APIs","Watch for underflow when computing offsets by subtraction","Never pass raw user input as offset without checks"],"tags":["collections","deque","argument-out-of-range","offset"],"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-16T04:17:20.429Z"}