LinusU / react-native-get-random-values

A small implementation of `getRandomValues` for React Native
MIT License
350 stars 48 forks source link

v1.9.0 throws "unordered_map::at: key not found" error #49

Open landabaso opened 1 year ago

landabaso commented 1 year ago

When executing version v1.9.0 of the library, an exception is thrown at this line: global.expo.modules.ExpoCrypto.getRandomValues(array).

Here's the full error log:

ERROR  Error: Exception in HostFunction: unordered_map::at: key not found, js engine: hermes

I am utilizing this package alongside randombytes.

The array variable, which originates from randombytes, is initialized at this location.

Additional context that might be helpful:

For further clarity, I've tracked the function call in version v1.8.0, and it ultimately leads to global.ExpoModules.ExpoRandom.getRandomBase64String(byteLength);, which runs without any hitches.

For now, I've reverted to using v1.8.0. Appreciate the efforts behind this library, and I hope this information aids in resolving the issue.

LinusU commented 1 year ago

Thank you for taking the time to investigate and report!

Are you able to reproduce this if you just run the following lines, without this library at all?

const array = new Uint8Array(10)
global.expo.modules.ExpoCrypto.getRandomValues(array)

and do you get the same error if you import getRandomValues from expo-crypto and call that directly?

Also, which version of Expo are you using? and does the same error happen even if you remove your global Buffer polyfill?

Mastaleru commented 1 year ago

Example to reproduce this issue: repo: https://github.com/Mastaleru/rn-learn/tree/625f9d2791442e622f85c4d46cb1e9317c2bbfee/first_project package.json

  "dependencies": {
    "expo": "~49.0.13",
    "expo-status-bar": "~1.6.0",
    "react": "18.2.0",
    "react-native": "0.72.5",
    "react-native-get-random-values": "^1.9.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },

More context:

CarlosVilasAlvarez commented 11 months ago

Same behaviour, after v1.9.0 it crashes using expo v49 with realm-js (which needs this polyfill to run safely).

gvanderclay commented 5 months ago

This is still occurring on v1.11.0 with expo 51 and realm 12.