{"record":{"id":"3a0fe1300b405b4a","repo":"jstedfast/MailKit","slug":"outputoffset","errorCode":null,"errorMessage":"outputOffset","messagePattern":"outputOffset","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/DES.cs","lineNumber":123,"sourceCode":"\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{\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\tvar output = new byte[8];\n\n\t\t\t\tengine.ProcessBlock (inputBuffer, inputOffset, output, 0);","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/DES.cs#L105-L141","documentation":"DES.TransformBlock validates outputOffset with ArgumentOutOfRangeException: it must be >= 0 and allow 8 bytes to be written, i.e. outputOffset <= outputBuffer.Length - 8. This guarantees the cipher never writes past the end of the destination buffer.","triggerScenarios":"Calling TransformBlock with outputOffset < 0 or outputOffset > outputBuffer.Length - 8, e.g. writing to the tail of an output buffer that is too small for one more block.","commonSituations":"Output buffer allocated exactly for the message but loop writes one block too many; offset math off by 8 after the last chunk; buffer downsized between iterations.","solutions":["Size the output buffer as a multiple of 8 bytes (or input length rounded up) and advance outputOffset by 8 per block.","Before each call, assert outputOffset + 8 <= outputBuffer.Length.","Fix loop bounds so the last iteration's offset still leaves room for a full block."],"exampleFix":"// before\ndes.TransformBlock(input, i, 8, output, i); // output too small near end\n\n// after\nif (i + 8 <= output.Length)\n    des.TransformBlock(input, i, 8, output, i);","handlingStrategy":"validation","validationCode":"if (outputOffset >= 0 && outputOffset + 8 <= outputBuffer.Length)\n    des.TransformBlock(input, 0, 8, outputBuffer, outputOffset);","typeGuard":"static bool OutputFits(byte[] buf, int off) => off >= 0 && off + 8 <= buf.Length;","tryCatchPattern":"try {\n    des.TransformBlock(input, 0, 8, output, outOff);\n} catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"outputOffset\") {\n    // grow the output buffer or fix the offset before retrying\n}","preventionTips":["Size output buffers as ceil(len/8)*8 and advance offset by 8 per block.","Assert outputOffset + 8 <= output.Length inside the transform loop.","Fix loop bounds so the final chunk still fits in the output buffer."],"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"}