You need to sign in or sign up before continuing.
Function MDFile returns inappropriate result if IO error occurs
Consider this piece of code:
program test;
uses
md5;
const
nonexistingfile = ':non-existing:/\|'; //should not exist on any system
var
Context: TMDContext;
Digest: TMDDigest;
begin
writeln(MDPrint(MDFile(nonexistingfile, MD_VERSION_5)));
//basically the same as:
MDInit(Context, MD_VERSION_5);
MDFinal(Context, Digest);
writeln(MDPrint(Digest));
end.
It outputs:
d41d8cd98f00b204e9800998ecf8427e
d41d8cd98f00b204e9800998ecf8427e
I don't think a non-existing file should have a valid MD5.
The issue is caused by the fact that inside TMDDigest()
if opening the file fails, the function does not exit with some sort of result indicating an error, but just finalizes the context.
Maybe in case of error it should return Default(TMDDigest) instead?
Originally reported on the forum by user Tommi.