jstedfast/MailKit · error · ArgumentOutOfRangeException
offset
Error message
offset
What it means
Guard in HMACMD5.ComputeHash: the 'offset' argument (start position in the input buffer) was negative or greater than the buffer length, so no valid slice of the buffer can be hashed; ArgumentOutOfRangeException is thrown before hashing.
Solutions
- Validate 0 <= offset <= buffer.Length before the call
- Reset the running offset when starting a new hash computation
- Catch ArgumentOutOfRangeException and log buffer length vs offset
Example fix
// before hmac.ComputeHash(buf, pos, buf.Length - pos); // pos may exceed buf.Length // after if (pos >= 0 && pos <= buf.Length) hmac.ComputeHash(buf, pos, buf.Length - pos);
Defensive patterns
Strategy: validation
Validate before calling
if (offset < 0 || offset > buffer.Length) throw new ArgumentException("offset out of bounds"); Try / catch
try { hmac.ComputeHash(buf, off, cnt); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "offset") { /* reset offset */ } Prevention
- Reset running offsets per message
- Assert offset bounds before hashing
- Use offset-free ComputeHash overloads when possible
When it happens
Trigger: Passing a negative offset or one beyond the end of the buffer, e.g. offsets carried over from previous chunked hashing.
Common situations: Streaming NTLM message signing where a running offset overruns the accumulated buffer.
Related errors
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/9409b5dc409e2755.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Security/Ntlm/HMACMD5.cs:106
}
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)
{
if (buffer == null)
throw new ArgumentNullException (nameof (buffer));
View on GitHub (pinned to 9d3859a785)