bignumber.js: Infinite loop in Safari 10.1
There appears to be an infinite loop in https://github.com/MikeMcl/bignumber.js/blob/46ed093a78e4061efeac50c1bbae624ad61a33f2/bignumber.js#L918-L925 for new versions of Webkit, including the newly released Safari 10.1
(new BigNumber(2043150)).dividedBy(10000);
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 48 (19 by maintainers)
Commits related to this issue
- swtich back to main bignumber.js repository https://github.com/MikeMcl/bignumber.js/issues/120 — committed to krachtstefan/runverter by krachtstefan 7 years ago
- Fixed the issue: the shift and unshift of array broken under iOS 10.3.1 and 10.3.2 Ref: https://github.com/MikeMcl/bignumber.js/issues/120 — committed to ls-simon-he/big.js by ls-simon-he 7 years ago
- Fixed the shift and unshift issues on iOS 10.3.1 and 10.3.2 Ref: KO-9712 & https://github.com/MikeMcl/bignumber.js/issues/120 — committed to kounta/big.js by ls-simon-he 7 years ago
- Mimic unshift method with array concat to workaround safari bug — committed to MikeMcl/bignumber.js by deleted user 7 years ago
I’ve published v4.0.2 which uses Jamie’s above workaround to resolve this issue. Thank you to all contributors.
Amazing! Thanks for diligent testing @dfrencham 💯
Your isolation of failing tests lead me to discover that the
.unshift()method is also affected. I’ve yet to find exact code to replicate the bug, but changing the unshift here to an alternative allowedbase-outtests to pass. Changing the rest fixed the test suite.I’ve added a workaround to my fork using
Array.prototype.concatto mimic unshift. The tests now ALL PASS on Safari 10.1 for myself locally 🎉 . Are you able to confirm validity of tests? 😄These workarounds have probably slowed the performance down a little as native shift/unshift will be faster.
The failing test suites above worry me greatly. I think it’s safe to assume that if you’re using bignumber.js in your app or library and have users on latest stable iOS/Safari browsers any calculations in the last 30ish days could be inaccurate… 😱
I logged it as a webkit bug here: https://bugs.webkit.org/show_bug.cgi?id=170264
+1’s on the bug ticket would be appreciated (add a comment and say you’re seeing the same behaviour).
thank you. it bugs in the browser. Array#shift
(smaller 2147483647, it works collectly.)
fix to bug
I’ll trying report to Apple.
I implemented the workaround I suggested in my fork. You could use it as a temporary workaround
https://github.com/Ka0o0/bignumber.js
@krachtstefan
It’s
v4.0.2and I’ve just pushed the tag now. Thanks for the reminder.@jamsinclair all tests are passing here mate. The failing tests are a bit of a worry, we count our user base in the millions, with a significant percentage using IOS.
@MikeMcl thanks for pushing that through, much appreciated!
Mimicking shift via splice seems to work in affected Apple browsers:
@MikeMcl I understand you’d rather have this issue resolved by Apple, but after 30 day it seems in limbo whether this is happening soon.
I have a fork and PR here #122. Should hopefully allow reliable calculations with bignumber.js in affected Apple browsers.
Let me know if I can make any changes or help 😄
Edit Update
The browser test
/test/browser/every-test.htmlfails and hangs in Safari 10.1 with and without my change 😢All tests pass with Safari Preview 10.2 and the rest of the browser gang (Chrome, FF, Opera, Edge)
Anyone able to confirm/replicate this?
Looks like the webkit bug maybe affecting the library in other ways than just the
.shift()hypothesis.