jstedfast/MailKit · error · ArgumentNullException
outputBuffer
Error message
outputBuffer
What it means
DES.TransformBlock throws ArgumentNullException with parameter name "outputBuffer" when the destination array is null. After validating the input, it checks that a real buffer exists to receive the encrypted/decrypted block before writing to outputOffset.
Solutions
- Allocate an output array of at least 8 bytes at outputOffset before calling.
- If you intended in-place transformation, pass the input buffer as the output buffer (DES allows same-buffer operation at the same offset).
- Verify the output variable assignment isn't conditional code that skipped initialization.
Example fix
// before des.TransformBlock(input, 0, 8, output, 0); // output null // after var output = new byte[8]; des.TransformBlock(input, 0, 8, output, 0);
Defensive patterns
Strategy: validation
Validate before calling
var output = outputBuffer ?? new byte[8]; des.TransformBlock(input, 0, 8, output, 0);
Type guard
static bool CanHoldBlock(byte[] buf, int off) => buf != null && off + 8 <= buf.Length;
Try / catch
try {
des.TransformBlock(input, 0, 8, output, 0);
} catch (ArgumentNullException ex) when (ex.ParamName == "outputBuffer") {
// allocate output and retry
output = new byte[8];
} Prevention
- Allocate the output buffer (>= 8 bytes, block-aligned for loops) before starting the transform.
- For in-place transforms pass the same buffer for input and output.
- Don't reuse null-output size-query patterns from other crypto APIs.
When it happens
Trigger: Calling des.TransformBlock(input, 0, 8, null, 0) — outputBuffer null even when you intend only to measure size (not supported by this transform).
Common situations: APIs that allow a null output to query required size being misused against this block transform; an uninitialized output array variable; refactoring that changed in-place transformation to separate output buffers.
Related errors
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/ea345cfb96f4d0c2.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Security/Ntlm/DES.cs:120
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);
}
public byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)
{
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");
View on GitHub (pinned to 9d3859a785)