{"record":{"id":"02c669c5aa8342f3","repo":"jstedfast/MailKit","slug":"inputoffset","errorCode":null,"errorMessage":"inputOffset","messagePattern":"inputOffset","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/DES.cs","lineNumber":111,"sourceCode":"\t\t\tpublic bool CanTransformMultipleBlocks {\n\t\t\t\tget { return false; }\n\t\t\t}\n\n\t\t\tpublic int InputBlockSize {\n\t\t\t\tget { return 8; }\n\t\t\t}\n\n\t\t\tpublic int OutputBlockSize {\n\t\t\t\tget { return 8; }\n\t\t\t}\n\n\t\t\tpublic int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)\n\t\t\t{\n\t\t\t\tif (inputBuffer == null)\n\t\t\t\t\tthrow new ArgumentNullException (\"inputBuffer\");\n\n\t\t\t\tif (inputOffset < 0 || inputOffset > inputBuffer.Length)\n\t\t\t\t\tthrow new ArgumentOutOfRangeException (\"inputOffset\");\n\n\t\t\t\tif (inputCount < 0 || inputOffset > inputBuffer.Length - inputCount)\n\t\t\t\t\tthrow new ArgumentOutOfRangeException (\"inputCount\");\n\n\t\t\t\tif (inputCount != 8)\n\t\t\t\t\tthrow new ArgumentOutOfRangeException (\"inputCount\", \"Can only transform 8 bytes at a time.\");\n\n\t\t\t\tif (outputBuffer == null)\n\t\t\t\t\tthrow new ArgumentNullException (\"outputBuffer\");\n\n\t\t\t\tif (outputOffset < 0 || outputOffset > outputBuffer.Length - 8)\n\t\t\t\t\tthrow new ArgumentOutOfRangeException (\"outputOffset\");\n\n\t\t\t\treturn engine.ProcessBlock (inputBuffer, inputOffset, outputBuffer, outputOffset);\n\t\t\t}\n\n\t\t\tpublic byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount)\n\t\t\t{","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/DES.cs#L93-L129","documentation":"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.","triggerScenarios":"Calling TransformBlock with inputOffset < 0 or inputOffset > inputBuffer.Length, e.g. a miscomputed offset when processing a byte stream in 8-byte chunks.","commonSituations":"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.","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."],"exampleFix":"// before\ndes.TransformBlock(buf, off, 8, out, 0); // off may exceed buf.Length\n\n// after\nif (off >= 0 && off <= buf.Length - 8)\n    des.TransformBlock(buf, off, 8, out, 0);","handlingStrategy":"validation","validationCode":"if (inputOffset >= 0 && inputOffset <= inputBuffer.Length)\n    des.TransformBlock(inputBuffer, inputOffset, 8, outputBuffer, 0);","typeGuard":"static bool ValidOffset(byte[] buf, int off) => off >= 0 && off <= buf.Length;","tryCatchPattern":"try {\n    des.TransformBlock(buf, off, 8, outBuf, 0);\n} catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"inputOffset\") {\n    // recompute offset from buffer length before retrying\n}","preventionTips":["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."],"tags":["mailkit","ntlm","des","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}