jstedfast/MailKit · error · ArgumentNullException
inputBuffer
Error message
inputBuffer
What it means
DES.TransformBlock (MailKit's internal NTLM DES implementation) throws ArgumentNullException with parameter name "inputBuffer" when the input byte array is null. The block cipher needs a real 8-byte input block to encrypt/decrypt, so the null check is the first validation performed.
Solutions
- Pass a valid non-null byte array containing the data block to transform.
- Verify the upstream key derivation (e.g., DES password hashing for NTLM) actually produced a buffer.
- Prefer computing via the higher-level APIs (NtlmTransform/ComputeDesMac style helpers) rather than the raw transform when available.
Example fix
// before
des.TransformBlock(input, 0, 8, output, 0); // input may be null
// after
if (input != null)
des.TransformBlock(input, 0, 8, output, 0); Defensive patterns
Strategy: validation
Validate before calling
if (input == null || input.Length < 8) throw new InvalidOperationException("need a full 8-byte DES block");
des.TransformBlock(input, 0, 8, output, 0); Type guard
static bool IsValidBlock(byte[] b, int off) => b != null && off >= 0 && off + 8 <= b.Length;
Try / catch
try {
des.TransformBlock(inputBuffer, inputOffset, 8, outputBuffer, 0);
} catch (ArgumentNullException ex) when (ex.ParamName == "inputBuffer") {
// null input: initialize or abort
} Prevention
- Verify key-derivation outputs are non-null before transforming.
- Prefer invariants: input buffer always assigned at construction of the transform loop.
- Use Debug.Assert for preconditions in NTLM helper code during development.
When it happens
Trigger: Calling des.TransformBlock(null, 0, 8, output, 0) — any invocation with a null inputBuffer, regardless of offset/count values.
Common situations: Using the internal MailKit.Security.Ntlm DES class directly for NTLM session keys; passing a key/password-derived buffer that failed to initialize; migrating code that relied on .NET's ICryptoTransform with a null input by mistake.
Related errors
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/88539de559f6bbaa.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Security/Ntlm/DES.cs:108
get { return false; }
}
public bool CanTransformMultipleBlocks {
get { return false; }
}
public int InputBlockSize {
get { return 8; }
}
public int OutputBlockSize {
get { return 8; }
}
public int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
if (inputBuffer == null)
throw new ArgumentNullException ("inputBuffer");
if (inputOffset < 0 || inputOffset > inputBuffer.Length)
throw new ArgumentOutOfRangeException ("inputOffset");
if (inputCount < 0 || inputOffset > inputBuffer.Length - inputCount)
throw new ArgumentOutOfRangeException ("inputCount");
if (inputCount != 8)
throw new ArgumentOutOfRangeException ("inputCount", "Can only transform 8 bytes at a time.");
if (outputBuffer == null)
throw new ArgumentNullException ("outputBuffer");
if (outputOffset < 0 || outputOffset > outputBuffer.Length - 8)
throw new ArgumentOutOfRangeException ("outputOffset");
return engine.ProcessBlock (inputBuffer, inputOffset, outputBuffer, outputOffset);
}View on GitHub (pinned to 9d3859a785)