jstedfast/MailKit · error · ArgumentNullException
inputBuffer
Error message
inputBuffer
What it means
TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) throws ArgumentNullException named "inputBuffer" when the input array is null. TransformBlock implements the ICryptoTransform pattern, so MD4 validates parameters exactly like the framework's crypto transforms do before touching hash state.
Solutions
- Pass a real (possibly empty) array: TransformBlock(Array.Empty<byte>(), 0, 0, null, 0) for a no-op block.
- Fix the buffer allocation that yielded null (allocate before the loop, not conditionally inside it).
- Guard incremental loops: only call TransformBlock when buffer != null.
- Catch ArgumentNullException at the boundary to identify the null input clearly.
Example fix
// before
transform.TransformBlock(chunk, 0, chunk.Length, null, 0); // chunk may be null
// after
if (chunk != null && chunk.Length > 0)
transform.TransformBlock(chunk, 0, chunk.Length, null, 0); Defensive patterns
Strategy: validation
Validate before calling
if (inputBuffer == null)
throw new ArgumentNullException(nameof(inputBuffer), "Provide a buffer (use Array.Empty<byte>() for no-op blocks)");
transform.TransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); Type guard
static bool CanTransform(byte[] input) => input != null;
Try / catch
try { transform.TransformBlock(input, 0, input.Length, null, 0); }
catch (ArgumentNullException ex) when (ex.ParamName == "inputBuffer") { log.LogError(ex, "Null input block"); throw; } Prevention
- Allocate the chunk buffer before the incremental loop
- Never pass null where an empty array is meant
- Skip the call entirely for null/empty chunks
When it happens
Trigger: Calling TransformBlock(null, 0, len, null, 0) — typical when feeding a null buffer from a streaming loop whose read buffer wasn't allocated, or passing null intentionally assuming an empty update.
Common situations: Hand-rolled incremental hashing in NTLM code (hashing key/message in pieces) where a buffer variable stays null on first iteration; refactored code that replaced a real buffer with null to "skip" a block.
Related errors
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/a7fae552fcf8a1d6.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Security/Ntlm/MD4.cs:342
var buffer = new byte[4096];
int nread;
do {
if ((nread = inputStream.Read (buffer, 0, buffer.Length)) > 0)
HashCore (buffer, 0, nread);
} while (nread > 0);
hashValue = HashFinal ();
Initialize ();
return hashValue;
}
public int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
if (inputBuffer == null)
throw new ArgumentNullException (nameof (inputBuffer));
if (inputOffset < 0 || inputOffset > inputBuffer.Length)
throw new ArgumentOutOfRangeException (nameof (inputOffset));
if (inputCount < 0 || inputOffset > inputBuffer.Length - inputCount)
throw new ArgumentOutOfRangeException (nameof (inputCount));
if (outputBuffer != null) {
if (outputOffset < 0 || outputOffset > outputBuffer.Length - inputCount)
throw new ArgumentOutOfRangeException (nameof (outputOffset));
}
HashCore (inputBuffer, inputOffset, inputCount);
if (outputBuffer != null)
Buffer.BlockCopy (inputBuffer, inputOffset, outputBuffer, outputOffset, inputCount);
return inputCount;View on GitHub (pinned to 9d3859a785)