{"record":{"id":"9409b5dc409e2755","repo":"jstedfast/MailKit","slug":"offset-hmacmd5","errorCode":null,"errorMessage":"offset","messagePattern":"offset","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/HMACMD5.cs","lineNumber":106,"sourceCode":"\t\t}\n\n\t\tpublic void Initialize ()\n\t\t{\n\t\t\thash.Init (new KeyParameter (Key));\n\t\t}\n\n\t\tpublic void Clear ()\n\t\t{\n\t\t\tDispose (false);\n\t\t}\n\n\t\tpublic byte[] ComputeHash (byte[] buffer, int offset, int count)\n\t\t{\n\t\t\tif (buffer == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (buffer));\n\n\t\t\tif (offset < 0 || offset > buffer.Length)\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (offset));\n\n\t\t\tif (count < 0 || offset > buffer.Length - count)\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (count));\n\n\t\t\tif (disposed)\n\t\t\t\tthrow new ObjectDisposedException (\"HashAlgorithm\");\n\n\t\t\tHashCore (buffer, offset, count);\n\t\t\thashValue = HashFinal ();\n\n\t\t\treturn hashValue;\n\t\t}\n\n\t\tpublic byte[] ComputeHash (byte[] buffer)\n\t\t{\n\t\t\tif (buffer == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (buffer));\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/HMACMD5.cs#L88-L124","documentation":"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.","triggerScenarios":"Passing a negative offset or one beyond the end of the buffer, e.g. offsets carried over from previous chunked hashing.","commonSituations":"Streaming NTLM message signing where a running offset overruns the accumulated buffer.","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"],"exampleFix":"// before\nhmac.ComputeHash(buf, pos, buf.Length - pos); // pos may exceed buf.Length\n// after\nif (pos >= 0 && pos <= buf.Length)\n\thmac.ComputeHash(buf, pos, buf.Length - pos);","handlingStrategy":"validation","validationCode":"if (offset < 0 || offset > buffer.Length) throw new ArgumentException(\"offset out of bounds\");","typeGuard":null,"tryCatchPattern":"try { hmac.ComputeHash(buf, off, cnt); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"offset\") { /* reset offset */ }","preventionTips":["Reset running offsets per message","Assert offset bounds before hashing","Use offset-free ComputeHash overloads when possible"],"tags":["csharp","hmac","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"}