{"record":{"id":"c946a5205193852c","repo":"jstedfast/MailKit","slug":"inputstream","errorCode":null,"errorMessage":"inputStream","messagePattern":"inputStream","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"MailKit/Security/Ntlm/MD4.cs","lineNumber":319,"sourceCode":"\t\t\tHashCore (buffer, offset, count);\n\t\t\thashValue = HashFinal ();\n\t\t\tInitialize ();\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\n\t\t\treturn ComputeHash (buffer, 0, buffer.Length);\n\t\t}\n\n\t\tpublic byte[] ComputeHash (Stream inputStream)\n\t\t{\n\t\t\tif (inputStream == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (inputStream));\n\n\t\t\t// don't read stream unless object is ready to use\n\t\t\tif (disposed)\n\t\t\t\tthrow new ObjectDisposedException (nameof (MD4));\n\n\t\t\tvar buffer = new byte[4096];\n\t\t\tint nread;\n\n\t\t\tdo {\n\t\t\t\tif ((nread = inputStream.Read (buffer, 0, buffer.Length)) > 0)\n\t\t\t\t\tHashCore (buffer, 0, nread);\n\t\t\t} while (nread > 0);\n\n\t\t\thashValue = HashFinal ();\n\t\t\tInitialize ();\n\n\t\t\treturn hashValue;\n\t\t}","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Security/Ntlm/MD4.cs#L301-L337","documentation":"ComputeHash(Stream inputStream) throws ArgumentNullException named \"inputStream\" when the stream is null. Like the byte[] overload, MD4 validates the parameter up front before reading any data, matching standard HashAlgorithm behavior for streaming hashes.","triggerScenarios":"Calling md4.ComputeHash(stream) where the stream variable is null — e.g. File.OpenRead failed to be assigned, a factory method returned null, or a nullable property was passed unconditionally.","commonSituations":"Hashing a file whose open call was wrapped in try/catch that swallowed the error and left the stream null; pipeline code where an optional attachment/stream is absent; DI/factory returning null in tests.","solutions":["Ensure the stream is opened successfully and non-null before hashing; propagate open failures instead of swallowing them.","Guard with if (stream != null) or throw a descriptive exception for missing input at a higher level.","If null means \"no data\", decide explicitly: either skip hashing or hash an empty byte array via ComputeHash(Array.Empty<byte>()).","Catch ArgumentNullException at the API boundary to report missing input clearly."],"exampleFix":"// before\nusing (var stream = path != null ? File.OpenRead(path) : null)\n    hash = md4.ComputeHash(stream); // NRE/ANG when path == null\n// after\nif (!File.Exists(path)) throw new FileNotFoundException(path);\nusing (var stream = File.OpenRead(path))\n    hash = md4.ComputeHash(stream);","handlingStrategy":"validation","validationCode":"if (inputStream == null) throw new ArgumentNullException(nameof(inputStream));\nvar hash = md4.ComputeHash(inputStream);","typeGuard":"static bool CanHash(Stream s) => s != null;","tryCatchPattern":"try { hash = md4.ComputeHash(stream); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"inputStream\") { log.LogError(ex, \"Stream not opened\"); throw; }","preventionTips":["Check File.Exists / open errors before hashing files","Never swallow stream-open exceptions leaving the variable null","Decide explicitly what null input means: skip, default, or error"],"tags":["argument-exception","null","hash","stream"],"backgroundTag":"null-argument","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"}