jstedfast/MailKit · error · ArgumentOutOfRangeException
inputOffset
Error message
inputOffset
What it means
DES.TransformBlock validates inputOffset with ArgumentOutOfRangeException: it must be >= 0 and <= inputBuffer.Length. A negative offset or an offset beyond the buffer is an indexing error MailKit catches before reading the block, instead of allowing an IndexOutOfRangeException or reading garbage.
Solutions
- Clamp/verify inputOffset is within [0, inputBuffer.Length] before the call.
- Fix the chunking loop so offset increments match the 8-byte block size.
- Check that the buffer wasn't replaced/shrunk between computing the offset and calling TransformBlock.
Example fix
// before
des.TransformBlock(buf, off, 8, out, 0); // off may exceed buf.Length
// after
if (off >= 0 && off <= buf.Length - 8)
des.TransformBlock(buf, off, 8, out, 0); Defensive patterns
Strategy: validation
Validate before calling
if (inputOffset >= 0 && inputOffset <= inputBuffer.Length)
des.TransformBlock(inputBuffer, inputOffset, 8, outputBuffer, 0); Type guard
static bool ValidOffset(byte[] buf, int off) => off >= 0 && off <= buf.Length;
Try / catch
try {
des.TransformBlock(buf, off, 8, outBuf, 0);
} catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "inputOffset") {
// recompute offset from buffer length before retrying
} Prevention
- Derive offsets from the buffer length in the loop condition, never from cached values.
- Recompute the offset after any buffer reallocation.
- Keep chunk stride (8) and offset increment in one constant.
When it happens
Trigger: Calling TransformBlock with inputOffset < 0 or inputOffset > inputBuffer.Length, e.g. a miscomputed offset when processing a byte stream in 8-byte chunks.
Common situations: Manual chunking loops that advance the offset by the wrong stride; offsets captured before a buffer resize/reallocation; off-by-one from including a header length incorrectly.
Related errors
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/02c669c5aa8342f3.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Security/Ntlm/DES.cs:111
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);
}
public byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)
{View on GitHub (pinned to 9d3859a785)