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
new BN(null).toString() causes an infinite loop (cashes the browser) #186
Comments
Also bumped into this. Running
Crashes Node with
|
When calling getBalance(), it was possible to sometimes get another value than an big integer as a string. Having `null` as a result, and passing it to the BN.js constructor, could lead to an infinit loop [1]. To prevent this issue to happen again: - In the app, `balance` is now always represented by a BN.js instance. To represent an unknown balance, `new BN(-1)` is now used rather than `null`. - The result of getbalance() is now filtered to ensure that we are passing an integer to BN.js. Otherwise, we pass "-1". [1] indutny/bn.js#186
When calling getBalance(), it was possible to sometimes get another value than an big integer as a string. Having `null` as a result, and passing it to the BN.js constructor, could lead to an infinit loop [1]. To prevent this issue to happen again: - In the app, `balance` is now always represented by a BN.js instance. To represent an unknown balance, `new BN(-1)` is now used rather than `null`. - The result of getbalance() is now filtered to ensure that we are passing an integer to BN.js. Otherwise, we pass "-1". [1] indutny/bn.js#186
Could you please resolve this issue and patch the codebase? We figured out that it is possible to trigger this bug by passing the following arguments: new BN(" ").toString()
new BN("-").toString()
new BN(null).toString()
new BN(undefined).toString() As the |
cc: @indutny Below is what we diagnosed with @ahpaleus. The crash occurs due to infinite loop which allocates memory on each loop iteration and so it exhausts the NodeJS or web browser's tab memory. Related sources:
Cases:
All those cases result in having a Lines 514 to 532 in db57519
This is because the Lines 2834 to 2836 in db57519
Also FWIW when All those could be fixed by additional assertions in the BN constructor. That could be e.g. |
new BN(null).toString()
causes an infinite loop (cashes the browser)It looks like
new BN(null)
creates an empty BN.toString()
causes the VM interpreter to go into a loopI think the solution is to make
.toString()
crash on empty instances.A better fix could be to no longer accept
new BN(null)
, remove empty instance feature or make it accessible with a different api (0 param constructor or something else).The text was updated successfully, but these errors were encountered: