BillyRayPreachersSon
Programmer
I'm working on a Firefox extension at the moment, and one of the things it does is hash files with the SHA512 algorithm, using Fx's nsICryptoHash interface.
It works really well, but I've just discovered that the hashing routines don't appear to work on files bigger than 2,147,483,647 bytes (the maximum value of a 32-bit signed int).
Unfortunately the docs ( are a bit misleading as they say that by passing in PR_UINT32_MAX, the whole file will be read - which is not what I'm seeing for files bigger than that limit.
As soon as I try and hash any file bigger than 2GB, I get the following error:
It occurs on the following line (the whole code sample can be found by visiting the link I gave above):
Even if I pass in a value greater than PR_UINT32_MAX, I still get the same error at the same line.
Which leaves me with two questions:
1) Can anyone think of a way around this problem while still performing the hashing in a Fx extension (that way it should work cross-OS, rather than calling out to an external tool where we have no idea what users will have on their PCs), and
2) If I were to hash smaller portions of the file, is their a way I can combine the individual hashes to still come up with the same checksum overall? I don't know enough about how SHA512 works to know.
Thanks!
Dan
Coedit Limited - Delivering standards compliant, accessible web solutions
Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
It works really well, but I've just discovered that the hashing routines don't appear to work on files bigger than 2,147,483,647 bytes (the maximum value of a 32-bit signed int).
Unfortunately the docs ( are a bit misleading as they say that by passing in PR_UINT32_MAX, the whole file will be read - which is not what I'm seeing for files bigger than that limit.
As soon as I try and hash any file bigger than 2GB, I get the following error:
Code:
Error: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsICryptoHash.updateFromStream]
It occurs on the following line (the whole code sample can be found by visiting the link I gave above):
Code:
ch.updateFromStream(istream, PR_UINT32_MAX);
Even if I pass in a value greater than PR_UINT32_MAX, I still get the same error at the same line.
Which leaves me with two questions:
1) Can anyone think of a way around this problem while still performing the hashing in a Fx extension (that way it should work cross-OS, rather than calling out to an external tool where we have no idea what users will have on their PCs), and
2) If I were to hash smaller portions of the file, is their a way I can combine the individual hashes to still come up with the same checksum overall? I don't know enough about how SHA512 works to know.
Thanks!
Dan
Coedit Limited - Delivering standards compliant, accessible web solutions
Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign