Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect result for ArrayBuffer #49

Open
rreusser opened this issue Mar 14, 2019 · 7 comments
Open

Incorrect result for ArrayBuffer #49

rreusser opened this issue Mar 14, 2019 · 7 comments

Comments

@rreusser
Copy link

rreusser commented Mar 14, 2019

Hi! Thanks for the great module! It's worked well for me, but I get the incorrect result for ArrayBuffer input, even if I wrap it in a Uint8Array. For example, and comparing to the js-md5 module:

> jsMd5 = require('js-md5')
> md5 = require('md5')

> buffer = new ArrayBuffer(9)
ArrayBuffer { byteLength: 9 }

> x = new Uint8Array(buffer)
Uint8Array [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]

> jsMd5(buffer)
'3f2829b2ffe8434d67f98a2a98968652'
> jsMd5(x)
'3f2829b2ffe8434d67f98a2a98968652'

> md5(buffer)
'441018525208457705bf09a8ee3c1093'
> md5(x)
'f3c8bdb6b9df478f227af2ce61c8a5a1'

Checking the hash of the bytes directly via https://cryptii.com/pipes/md5-hash confirms the js-md5 result :

Screen Shot 2019-03-14 at 10 24 12 AM

See also: #42

@nmeyvis
Copy link

nmeyvis commented Jul 26, 2019

Yep, ran into this today. It outputs the same 441018525208457705bf09a8ee3c1093 hash for all arraybuffers. Going to have to switch to a different package.

@maknahar
Copy link

maknahar commented Dec 2, 2019

Encountered the same issue with array.

const md5 = require('md5');
let theatreIds = ["040b163b-8797-4406-bf59-07c5445334aa","1d82af48-28b4-4845-aad7-69026ffa2a9f"]
console.log(md5(theatreIds))
// Output:c4103f122d27677c9db144cae1394a66
theatreIds = ["a2fcba9e-cc58-435a-b7c9-4a3c4fd8eb06","c0bc4f2b-daca-434a-a6f3-2321863d4362"]
console.log(md5(theatreIds))
// Output:c4103f122d27677c9db144cae1394a66

Will switch to a different package.

@stf1981
Copy link

stf1981 commented Feb 7, 2020

The code of the npm package is an older version. I think the current version was never released on npm.

@AlttiRi
Copy link

AlttiRi commented Jul 10, 2020

Yes, the current version on NPM does not support Uint8Array. It requires to wrap Uint8Array to Buffer via Buffer.from(data). In this case it works OK.

I think the author should note about it in README.md. Or better – update the package on NPM. #47 should fix this.

@AlttiRi
Copy link

AlttiRi commented Jul 10, 2020

Encountered the same issue with array.

const md5 = require('md5');
let theatreIds = ["040b163b-8797-4406-bf59-07c5445334aa","1d82af48-28b4-4845-aad7-69026ffa2a9f"]
console.log(md5(theatreIds))
// Output:c4103f122d27677c9db144cae1394a66
theatreIds = ["a2fcba9e-cc58-435a-b7c9-4a3c4fd8eb06","c0bc4f2b-daca-434a-a6f3-2321863d4362"]
console.log(md5(theatreIds))
// Output:c4103f122d27677c9db144cae1394a66

Will switch to a different package.

It's not the same issue.
You pass an array of strings to the function that does not accept an array of strings as the input argument. You just do the wrong thing.
In your case the output is correct.
This function accept an array of bytes. It's commonly for crypto functions.

https://github.com/pvorb/node-md5/blob/master/md5.js#L8-L19

@IOTA233
Copy link

IOTA233 commented Aug 3, 2021

Yes, the current version on NPM does not support Uint8Array. It requires to wrap Uint8Array to Buffer via Buffer.from(data). In this case it works OK.

I think the author should note about it in README.md. Or better – update the package on NPM. #47 should fix this.

thanks, this is work for me
const fileReader = new FileReader()
fileReader.readAsArrayBuffer(info.file.originFileObj)
fileReader.onload = e => {
this.value = md5(new Uint8Array(e.target.result))
}

@AlttiRi
Copy link

AlttiRi commented Aug 3, 2021

After my message the package was updated on 2020-08-02.
image

So now it supports Uint8Array.

Also you do not need to use FileReader to take ArrayBuffer:

md5(new Uint8Array(await file.arrayBuffer()))

josephfrazier added a commit to josephfrazier/reported-web that referenced this issue Aug 21, 2022
josephfrazier added a commit to josephfrazier/reported-web that referenced this issue Aug 22, 2022
josephfrazier added a commit to josephfrazier/reported-web that referenced this issue Aug 22, 2022
This fixes #361. Here's the whole saga:

Here's an example image that works on desktop, but not mobile: https://photos.app.goo.gl/AcEfSrYTMqgp6JfX8

Using [`eruda`](https://www.npmjs.com/package/eruda) to see the JS console with [this branch](#360), I see this on desktop:

```js
Extracted GPS latitude/longitude location from EXIF metadata Object {latitude: 40.717019444444446, longitude: -73.99356388888889}
```

but this on mobile:

```js
Extracted GPS latitude/longitude location from EXIF metadata Object {latitude: "NaN", longitude: "NaN"}
```

---

Seems like this issue might be within the `exifr` library: https://github.com/MikeKovarik/exifr

---

To rule out the possibility that the EXIF metadata is getting stripped when uploaded from my phone, [I logged out the md5sum of the image right before parsing the metadata](4208a1b), and it is `441018525208457705bf09a8ee3c1093` on both desktop and mobile, yet the `GPSLatitude` and `GPSLongitude` arrays are `[NaN, NaN, NaN]` on mobile, but `[40, 43, 1.27]`and `[73, 59, 36.83]` on desktop, respectively.

---

related exifr issue: MikeKovarik/exifr#64

---

> [I logged out the md5sum of the image right before parsing the metadata](4208a1b), and it is `441018525208457705bf09a8ee3c1093` on both desktop and mobile

Ugh, it looks like the package I chose to use might have a bug that causes this value to show up for ArrayBuffers: pvorb/node-md5#49

---

If I switch to [object-hash](https://github.com/puleos/object-hash), I get a sha1 of `b287c307cd89cfd2ce779b975b961b4824f2714a` on desktop, but it crashes on my phone, so I guess I need something less resource-intensive...

---

Seems like Android is stripping GPS from EXIF after all, when the `<input>` element has an `accept` attribute specifying images, but removing the attribute does the trick for me.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants