jstedfast/MailKit · error · ArgumentNullException
buffer
Error message
buffer
What it means
Guard in HMACMD5.ComputeHash: the 'buffer' argument (the input data to hash) was null. The hash computation needs a real byte array, so null is rejected with ArgumentNullException before range checks on offset/count.
Solutions
- Allocate or fetch the buffer before hashing
- Use ComputeHash(emptyArray) if hashing an empty payload intentionally
- Catch ArgumentNullException at the signing boundary
Example fix
// before hmac.ComputeHash(payload, 0, payload.Length); // after if (payload != null) hmac.ComputeHash(payload, 0, payload.Length);
Defensive patterns
Strategy: validation
Validate before calling
if (buffer == null) throw new ArgumentException("buffer must not be null"); Type guard
bool HasData(byte[] b) => b != null;
Try / catch
try { hmac.ComputeHash(buf, off, cnt); } catch (ArgumentNullException) { /* null payload */ } Prevention
- Use Array.Empty<byte>() for intentional empty payloads
- Null-check upstream message bodies
- Keep signing entry points defensive
When it happens
Trigger: Calling ComputeHash(null, 0, 0), often when the message body came from an upstream null value.
Common situations: NTLM signing of a message whose payload buffer was never populated.
Related errors
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/08ab35827c957443.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Security/Ntlm/HMACMD5.cs:103
hash.Reset ();
return value;
}
public void Initialize ()
{
hash.Init (new KeyParameter (Key));
}
public void Clear ()
{
Dispose (false);
}
public byte[] ComputeHash (byte[] buffer, int offset, int count)
{
if (buffer == null)
throw new ArgumentNullException (nameof (buffer));
if (offset < 0 || offset > buffer.Length)
throw new ArgumentOutOfRangeException (nameof (offset));
if (count < 0 || offset > buffer.Length - count)
throw new ArgumentOutOfRangeException (nameof (count));
if (disposed)
throw new ObjectDisposedException ("HashAlgorithm");
HashCore (buffer, offset, count);
hashValue = HashFinal ();
return hashValue;
}
public byte[] ComputeHash (byte[] buffer)
{View on GitHub (pinned to 9d3859a785)