{"record":{"id":"26a0e4f9af0e0bdd","repo":"jstedfast/MailKit","slug":"inputcount","errorCode":null,"errorMessage":"inputCount","messagePattern":"inputCount","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/DES.cs","lineNumber":114,"sourceCode":"\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{\n\t\t\t\tif (inputBuffer == null)\n\t\t\t\t\tthrow new ArgumentNullException (\"inputBuffer\");\n","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/DES.cs#L96-L132","documentation":"DES.TransformBlock validates inputCount with ArgumentOutOfRangeException: it must be >= 0 and inputOffset + inputCount must fit within inputBuffer (note the guard checks inputOffset > inputBuffer.Length - inputCount). A negative count or a range exceeding the buffer is rejected before any crypto work.","triggerScenarios":"Calling TransformBlock with inputCount < 0, or with inputCount such that inputOffset + inputCount exceeds inputBuffer.Length (e.g., asking to read 8 bytes from a 5-byte tail without shrinking the count).","commonSituations":"Processing the final partial block of a stream without handling the leftover bytes; count hardcoded to 8 while the buffer only holds fewer remaining bytes; sign-flipped lengths from int arithmetic overflow.","solutions":["Ensure inputCount is 8 for every block (this transform requires full blocks) and that the buffer actually contains 8 bytes at inputOffset.","Handle partial final blocks separately (pad or use TransformFinalBlock).","Validate count against buffer length: inputOffset + inputCount <= inputBuffer.Length."],"exampleFix":"// before\ndes.TransformBlock(buf, off, 8, out, 0); // fewer than 8 bytes remain\n\n// after\nif (buf.Length - off >= 8)\n    des.TransformBlock(buf, off, 8, out, 0);","handlingStrategy":"validation","validationCode":"int remaining = inputBuffer.Length - inputOffset;\nif (remaining >= 8)\n    des.TransformBlock(inputBuffer, inputOffset, 8, outputBuffer, 0);","typeGuard":"static bool FullBlockAvailable(byte[] buf, int off) => buf.Length - off >= 8;","tryCatchPattern":"try {\n    des.TransformBlock(buf, off, 8, outBuf, 0);\n} catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"inputCount\") {\n    // partial tail: pad or use TransformFinalBlock\n}","preventionTips":["Check remaining bytes (length - offset) before requesting a block.","Handle partial final blocks explicitly rather than forcing count = 8.","Avoid hardcoding counts that assume the buffer is block-aligned."],"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"}