{"record":{"id":"d50c9883f5a0ea62","repo":"jstedfast/MailKit","slug":"the-custom-data-must-be-8-bytes","errorCode":null,"errorMessage":"The custom data must be 8 bytes.","messagePattern":"The custom data must be 8 bytes\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/NtlmSingleHostData.cs","lineNumber":79,"sourceCode":"\t\t/// <param name=\"customData\">The 8-byte platform-specific blob.</param>\n\t\t/// <param name=\"machineId\">The 256-bit randomly generated machine id.</param>\n\t\t/// <exception cref=\"ArgumentNullException\">\n\t\t/// <para><paramref name=\"customData\"/> is <see langword=\"null\" />.</para>\n\t\t/// <para>-or-</para>\n\t\t/// <para><paramref name=\"machineId\"/> is <see langword=\"null\" />.</para>\n\t\t/// </exception>\n\t\t/// <exception cref=\"ArgumentException\">\n\t\t/// <para><paramref name=\"customData\"/> is not 8 bytes.</para>\n\t\t/// <para>-or-</para>\n\t\t/// <para><paramref name=\"machineId\"/> is not 32 bytes.</para>\n\t\t/// </exception>\n\t\tpublic NtlmSingleHostData (byte[] customData, byte[] machineId)\n\t\t{\n\t\t\tif (customData == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (customData));\n\n\t\t\tif (customData.Length != 8)\n\t\t\t\tthrow new ArgumentException (\"The custom data must be 8 bytes.\", nameof (customData));\n\n\t\t\tif (machineId == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (machineId));\n\n\t\t\tif (machineId.Length != 32)\n\t\t\t\tthrow new ArgumentException (\"The machine id must be 32 bytes.\", nameof (machineId));\n\n\t\t\tCustomData = customData;\n\t\t\tMachineId = machineId;\n\t\t\tSize = 48;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Get or set an 8-byte platform-specific blob.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// Gets or sets an 8-byte platform-specific blob.\n\t\t/// </remarks>","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/NtlmSingleHostData.cs#L61-L97","documentation":"The NtlmSingleHostData constructor throws ArgumentException when customData is not exactly 8 bytes. The NTLM Single_Host_Data format reserves a fixed 8-byte CustomData field, so any other length is invalid and rejected rather than truncated or padded.","triggerScenarios":"Calling new NtlmSingleHostData(customData, machineId) with customData.Length != 8 (e.g. a 4-byte or 16-byte slice from incorrect buffer math).","commonSituations":"Wrong slice boundaries when extracting customData from a 48-byte Single_Host_Data blob; confusing the 8-byte custom data with the 32-byte machine ID; copying a struct layout from a different NTLM variant.","solutions":["Extract exactly 8 bytes for customData (e.g. buffer.AsSpan(start, 8).ToArray())","Verify slicing offsets against the 48-byte Single_Host_Data layout","Pad or truncate a foreign value to 8 bytes only if that matches your protocol contract"],"exampleFix":"// before\nvar customData = new byte[4];\nnew NtlmSingleHostData(customData, machineId);\n// after\nvar customData = new byte[8];\nBuffer.BlockCopy(blob, start, customData, 0, 8);\nnew NtlmSingleHostData(customData, machineId);","handlingStrategy":"type-guard","validationCode":"if (customData is null || customData.Length != 8)\n    throw new ArgumentException(\"customData must be exactly 8 bytes\");","typeGuard":"static bool Is8Bytes(byte[] d) => d is { Length: 8 };","tryCatchPattern":"try { var d = new NtlmSingleHostData(customData, machineId); }\ncatch (ArgumentException ex) when (ex.ParamName == \"customData\") { /* fix slicing */ }","preventionTips":["Use spans with fixed lengths: buffer.AsSpan(off, 8).ToArray()","Document the 48-byte Single_Host_Data layout in parsing helpers","Unit-test blob slicing against a known-good sample"],"tags":["ntlm","argument-length","mailkit"],"backgroundTag":"invalid-argument-value","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}