indutny / bn.js

BigNum in pure javascript
MIT License
1.19k stars 150 forks source link

Fix Infinite loop when calling .toString() #296

Open ssch1337 opened 2 years ago

ssch1337 commented 2 years ago

If when initializing BigNumber pass '-' and call the .toString() function. An infinite loop will happen because BN.prototype.isZero() only fires if this.length === 1, in which case this.length === 0.

Example:

const BN = require('bn.js');
const a = new BN('-');
console.log(a.toString()); // Infinite loop