{"record":{"id":"84aabd4f5bb15f09","repo":"jstedfast/MailKit","slug":"specified-argument-was-out-of-the-range-of-valid-values-84aabd","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":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/NtlmMessageBase.cs","lineNumber":87,"sourceCode":"\t\t{\n\t\t\tfor (int i = 0; i < Signature.Length; i++) {\n\t\t\t\tif (message[startIndex + i] != Signature[i])\n\t\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn BitConverterLE.ToUInt32 (message, startIndex + 8) == Type;\n\t\t}\n\n\t\tprotected void ValidateArguments (byte[] message, int startIndex, int length)\n\t\t{\n\t\t\tif (message == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (message));\n\n\t\t\tif (startIndex < 0 || startIndex > message.Length)\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (startIndex));\n\n\t\t\tif (length < 12 || length > (message.Length - startIndex))\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (length));\n\n\t\t\tif (!CheckSignature (message, startIndex))\n\t\t\t\tthrow new ArgumentException (string.Format (CultureInfo.InvariantCulture, \"Invalid Type{0} message.\", Type), nameof (message));\n\n\t\t\tvar messageType = BitConverterLE.ToUInt32 (message, 8);\n\t\t\tif (messageType != Type)\n\t\t\t\tthrow new ArgumentException (string.Format (CultureInfo.InvariantCulture, \"Invalid Type{0} message.\", Type), nameof (message));\n\t\t}\n\n\t\tpublic abstract byte[] Encode ();\n\t}\n}\n","sourceCodeStart":69,"sourceCodeEnd":100,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/NtlmMessageBase.cs#L69-L100","documentation":"NtlmMessageBase.ValidateArguments() throws ArgumentOutOfRangeException when decoding an NTLM message byte array with a startIndex that is negative or beyond the end of the buffer. The library validates all positional arguments before parsing any message fields, since reading outside the buffer would produce garbage or crash. It guards every call to Decode-style methods (e.g. NtlmChallengeResponse.Decode, NtlmAuthenticate.Decode).","triggerScenarios":"Calling a decode/parse API (e.g. NtlmChallengeResponse.Decode or a Type1/Type2/Type3 message Load) with a startIndex < 0 or startIndex > message.Length on the supplied byte[].","commonSituations":"Passing a wrong slice offset after manually splitting an NTLM handshake buffer; reusing a stale startIndex after the buffer was re-sliced or shortened; off-by-one when skipping a fixed-size header.","solutions":["Verify startIndex is >= 0 and <= message.Length before calling the decode API","Recompute the offset from the actual buffer (e.g. use message.Length instead of a hard-coded constant)","If parsing a sub-message, slice with ArraySegment or copy the correct region first"],"exampleFix":"// before\nmsg.Decode(buffer, offset, buffer.Length - offset); // offset from wrong frame\n// after\nif (offset < 0 || offset > buffer.Length)\n    throw new InvalidOperationException(\"bad NTLM offset\");\nmsg.Decode(buffer, offset, buffer.Length - offset);","handlingStrategy":"validation","validationCode":"if (message == null) throw new ArgumentNullException(nameof(message));\nif (startIndex < 0 || startIndex > message.Length)\n    throw new ArgumentOutOfRangeException(nameof(startIndex));","typeGuard":"static bool IsValidRange(byte[] buf, int start) => buf != null && start >= 0 && start <= buf.Length;","tryCatchPattern":"try { msg.Decode(buffer, startIndex, length); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"startIndex\") { /* fix offset / skip message */ }","preventionTips":["Always compute startIndex from the actual buffer, never hard-code it","Assert buffer bounds before any manual NTLM parsing","Slice sub-messages into their own arrays to keep offsets at 0"],"tags":["ntlm","argument-out-of-range","mailkit"],"backgroundTag":"argument-out-of-range","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}