{"record":{"id":"2753ffdb5d8a4d78","repo":"dotnet/orleans","slug":"specified-argument-was-out-of-the-range-of-valid-v","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values.","messagePattern":"Specified argument was out of the range of valid values\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Azure/Orleans.Journaling.AzureStorage/ReadOnlySequenceStream.cs","lineNumber":39,"sourceCode":"            ObjectDisposedException.ThrowIf(_disposed, this);\n            return _sequence.Length;\n        }\n    }\n\n    public override long Position\n    {\n        get\n        {\n            ObjectDisposedException.ThrowIf(_disposed, this);\n            return _position;\n        }\n\n        set\n        {\n            ObjectDisposedException.ThrowIf(_disposed, this);\n            if (value < 0 || value > _sequence.Length)\n            {\n                throw new ArgumentOutOfRangeException(nameof(value));\n            }\n\n            _position = value;\n        }\n    }\n\n    public override void Flush() => ObjectDisposedException.ThrowIf(_disposed, this);\n\n    public override int Read(byte[] buffer, int offset, int count) => Read(buffer.AsSpan(offset, count));\n\n    public override int Read(Span<byte> buffer)\n    {\n        ObjectDisposedException.ThrowIf(_disposed, this);\n        if (buffer.IsEmpty || _position >= _sequence.Length)\n        {\n            return 0;\n        }\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/Azure/Orleans.Journaling.AzureStorage/ReadOnlySequenceStream.cs#L21-L57","documentation":"Thrown by the ReadOnlySequenceStream.Position setter when the assigned value is negative or greater than the sequence length. ReadOnlySequenceStream wraps a fixed ReadOnlySequence<byte>; positions outside [0, length] are invalid because there is no data to read there and the stream cannot grow.","triggerScenarios":"Setting stream.Position = -1, or a value larger than the underlying buffer length; or seeking/deriving a position that lands past the end (the setter is also reached via Seek).","commonSituations":"A deserializer computing an offset from a malformed length prefix; seeking to end+1 instead of end; arithmetic that underflows to negative; passing a stream length from an external source that disagrees with the actual buffer.","solutions":["Clamp the requested position to [0, stream.Length] before assigning.","Validate the source of the offset (e.g. content-length header) against stream.Length.","Use stream.Seek with SeekOrigin and bounds-check the result."],"exampleFix":"// before\nstream.Position = computedOffset; // computedOffset may be -1 or > Length\n// after\nstream.Position = Math.Clamp(computedOffset, 0, stream.Length);","handlingStrategy":"validation","validationCode":"if (value < 0 || value > stream.Length) throw new ArgumentOutOfRangeException(nameof(value));\nstream.Position = Math.Clamp(value, 0, stream.Length);","typeGuard":"static bool IsValidStreamPosition(Stream s, long p) => p >= 0 && p <= s.Length;","tryCatchPattern":null,"preventionTips":["Clamp positions to [0, Length] before assigning.","Validate externally sourced offsets (length prefixes) against Length.","Prefer stream.Seek with bounds-checked results over direct Position sets."],"tags":["azure-blob-storage","journaling","stream","argument-out-of-range","validation"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}