react-native-bignumber icon indicating copy to clipboard operation
react-native-bignumber copied to clipboard

Insta crash on Hermes but works with JSC

Open alexandrius opened this issue 2 years ago • 6 comments

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:

  • I commented out toArrayLike (inside commonjs/BigNumber.js) below here but weirdly the issue is still there. I wasn't able to find any toArrayLike invocations anywhere else

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

  • If I wrap if(ab.data(runtime) != NULL) the issue goes away but application doesn't behave correctly.

I would appreciate any suggestions. Thanks!

alexandrius avatar Jan 23 '23 19:01 alexandrius

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

mrousavy avatar Jan 25 '23 13:01 mrousavy

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.

kewde avatar Jan 26 '23 15:01 kewde

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.

JuanRdBO avatar Jul 26 '23 18:07 JuanRdBO

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

mordonez-me avatar Sep 21 '23 11:09 mordonez-me

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

JuanRdBO avatar Apr 21 '24 03:04 JuanRdBO

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

alexandrius avatar Apr 22 '24 08:04 alexandrius