Incorrect hash generated when binary data is supplied using a binary string.
- Dominant language
- JavaScript
- Stars
- 323
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
An incorrect hash is may be generated if a binary string is used. In my case, I was obtaining the string from a FileReader instance's [readAsBinaryString()](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsBinaryString) method. It seems to work fine with text files, but binary files throw it off and silently give the wrong hash. Using the recommended method of [readAsArrayBuffer()](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsArrayBuffer) works fine as long as you convert it to Uint8Array before passing it to the hasher via update().
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by inspecting the hasher's update() handling of binary strings and reproduce the mismatch with data from FileReader.readAsBinaryString(), comparing it with readAsArrayBuffer() converted to Uint8Array. Confirm the expected hash for binary data and add regression coverage showing that both supported input forms produce the same result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cryptography
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100