{"record":{"id":"b47434b45001d208","repo":"jstedfast/MailKit","slug":"specified-argument-was-out-of-the-range-of-valid-values-b47434","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/NtlmSingleHostData.cs","lineNumber":131,"sourceCode":"\t\t/// <summary>\n\t\t/// Get the size of the SingleHostData structure.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets the size of the SingleHostData structure.\n\t\t/// </remarks>\n\t\t/// <value>The size of the SingleHostData structure.</value>\n\t\tpublic int Size {\n\t\t\tget; private set;\n\t\t}\n\n\t\t[MemberNotNull (nameof (CustomData), nameof (MachineId))]\n\t\tvoid Decode (byte[] buffer, int startIndex, int length)\n\t\t{\n\t\t\tif (buffer == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (buffer));\n\n\t\t\tif (startIndex < 0 || startIndex > buffer.Length)\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (startIndex));\n\n\t\t\tif (length < 48 || length > (buffer.Length - startIndex))\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (length));\n\n\t\t\tint index = startIndex;\n\n\t\t\t// Size (4 bytes): A 32-bit unsigned integer that defines the length, in bytes, of the Value field in the AV_PAIR (section 2.2.2.1) structure.\n\t\t\tSize = BitConverterLE.ToInt32 (buffer, index);\n\t\t\tindex += 4;\n\n\t\t\t// Z4 (4 bytes): A 32-bit integer value containing 0x00000000.\n\t\t\tindex += 4;\n\n\t\t\t// CustomData (8 bytes): An 8-byte platform-specific blob containing info only relevant when the client and the server are on the same host.\n\t\t\tCustomData = new byte[8];\n\t\t\tBuffer.BlockCopy (buffer, index, CustomData, 0, 8);\n\t\t\tindex += 8;\n","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/NtlmSingleHostData.cs#L113-L149","documentation":"NtlmSingleHostData.Decode throws ArgumentOutOfRangeException when startIndex is negative or points past the end of the buffer. Since the structure is fixed at 48 bytes, the decoder must have a valid starting position within the supplied blob. Validation happens before any field is read.","triggerScenarios":"Calling the blob constructor / Decode with startIndex < 0 or startIndex > buffer.Length, e.g. an offset past the end of the target-info AV-pair buffer.","commonSituations":"Computing the Single_Host_Data offset from AV-pair walking that overran the buffer; passing the length as the offset; off-by-one after skipping a 4-byte AV header.","solutions":["Validate startIndex is within [0, buffer.Length] before decoding","Recompute the offset from the AV-pair walk, bounding it by buffer.Length","Slice the exact 48-byte region first and decode it at index 0"],"exampleFix":"// before\nvar singleHost = new NtlmSingleHostData(buffer, offset, 48); // offset can exceed buffer\n// after\noffset = Math.Min(offset, buffer.Length - 48);\nif (offset >= 0)\n    var singleHost = new NtlmSingleHostData(buffer, offset, 48);","handlingStrategy":"validation","validationCode":"if (buffer == null || startIndex < 0 || startIndex + 48 > buffer.Length)\n    throw new ArgumentOutOfRangeException(nameof(startIndex));","typeGuard":"static bool CanDecodeAt(byte[] b, int start) => b != null && start >= 0 && start + 48 <= b.Length;","tryCatchPattern":"try { var d = new NtlmSingleHostData(buffer, offset, 48); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"startIndex\") { /* recompute AV-pair offset */ }","preventionTips":["Bound every AV-pair walk by buffer.Length","Clamp computed offsets before decoding","Slice the structure out first, then decode at index 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-16T04:17:20.429Z"}