margelo / react-native-bignumber

🔢 The fastest Big Number library for React Native
https://margelo.io
MIT License
339 stars 11 forks source link

Insta crash on Hermes but works with JSC #56

Open alexandrius opened 1 year ago

alexandrius commented 1 year ago

Hey friends 👋,

I recently enabled this library in a project. Everything seemingly went through until I enabled Hermes engine. The app crashes immediately after launching with error:

error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x0).
The process has been returned to the state before expression evaluation.

I found out that the issue happens in either of these methods BN_bn2lebinpad, BN_bn2binpad: https://github.com/margelo/react-native-bignumber/blob/56873d9930f47379233edd183eec4454c6d97db3/cpp/MGBigNumberHostObject.cpp#L138-L145

Here's value of ab: Screenshot 2023-01-24 at 12 05 06 PM

What I tried so far:

https://github.com/margelo/react-native-bignumber/blob/56873d9930f47379233edd183eec4454c6d97db3/src/BigNumber.ts#L247-L252

I would appreciate any suggestions. Thanks!

mrousavy commented 1 year ago

oh weird, maybe we use ArrayBuffer wrong, Hermes should have native support for that.... cc @Szymon20000

kewde commented 1 year ago

Hermes doesn't allocate any memory for an ArraysBuffer's dataBuffer if the size is 0. It's a nullpointer.. The code also doesn't check if the ArrayBuffer size is sufficiently large to carry the BigNumber's data and potentially overflows.

JuanRdBO commented 1 year ago

Any news on this? I would be excited to implement this library into my app. But this exact same issue is causing my app to insta-crash as well.

mordonez-me commented 10 months ago

Hello guys, do you guys have plans for fixing this bug? I am having an insta-crash like this: image

JuanRdBO commented 3 months ago

I'm having the same crash as above as well with @solana/web3.js

alexandrius commented 3 months ago

To everyone struggling with this issue. I recommend migrating to BigInt