[PR #138] [CLOSED] Allow number values to exceed 32bits to support low unit value currencies #3041

Closed
opened 2026-02-28 20:35:27 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/138
Author: @TomAFrench
Created: 7/27/2022
Status: Closed

Base: masterHead: remove-32bit-limit-on-amounts


📝 Commits (10+)

  • 21f3199 fix: use integer check which doesn't require value to be 32 bit
  • 2f2e69a fix: use 64bit compatible integer check in aql compiler
  • a95f9ea fix: replace custom isInteger function with Number.isInteger
  • 74f797f fix: use Math.round in place of truncating digits
  • d69a897 fix: use Math.round in place of truncating digits
  • 5281623 fix: remove unnecessary conversion to 32 bit
  • 8d6ae15 fix: replace last usages of | 0
  • df19183 feat: add explicit value checking on saving to / reading from budget
  • 30ca82c Move safeNumber to shared util and tweak implementation
  • 6b8c6e2 Update packages/loot-core/src/mocks/index.js

📊 Changes

22 files changed (+97 additions, -71 deletions)

View changed files

📝 packages/api/utils.js (+1 -1)
📝 packages/desktop-electron/index.js (+2 -2)
📝 packages/loot-core/bin/profile-sql.js (+7 -7)
📝 packages/loot-core/src/client/queries.js (+1 -5)
📝 packages/loot-core/src/client/query-helpers.test.js (+1 -1)
📝 packages/loot-core/src/mocks/budget.js (+6 -6)
📝 packages/loot-core/src/mocks/index.js (+4 -4)
📝 packages/loot-core/src/server/aql/compiler.js (+1 -1)
📝 packages/loot-core/src/server/aql/schema-helpers.js (+1 -1)
📝 packages/loot-core/src/server/aql/schema/executors.test.js (+1 -1)
📝 packages/loot-core/src/server/budget/actions.js (+4 -5)
📝 packages/loot-core/src/server/budget/report.js (+9 -8)
📝 packages/loot-core/src/server/budget/rollover.js (+19 -15)
📝 packages/loot-core/src/server/budget/util.js (+6 -3)
📝 packages/loot-core/src/server/crdt/merkle.js (+1 -1)
📝 packages/loot-core/src/server/db/sort.js (+1 -1)
📝 packages/loot-core/src/server/sync/sync.property.test.js (+1 -1)
📝 packages/loot-core/src/shared/rules.js (+1 -1)
📝 packages/loot-core/src/shared/schedules.js (+1 -1)
📝 packages/loot-core/src/shared/util.js (+26 -3)

...and 2 more files

📄 Description

We currently prevent any values greater than 21,474,836.47 ( (2^31 - 1) / 100 ) from being written to the database as a side effect of how we check that the value is an integer.

While this is unlikely to cause issues for GBP/USD/EUR users (I'd love to run into this issue myself), it does impact users who use currencies where the unit value is lower for example INR as it manifests at ~250k USD. One user in the discord is encountering this with IDR which means they run into this bug when dealing with values of ~1.4k USD.

2147483647 | 0 == 2147483647
2147483648 | 0 == -2147483648

This is due to the fact we're performing a bitwise operation as value is being converted into a signed 32 bit number and back again, causing the overflow. I've replaced this with a non-bitwise integer check so that we support 64 bit numbers.


Tested by adding a huge value transaction to a fresh account:

Before:
image

After:
image


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/actualbudget/actual/pull/138 **Author:** [@TomAFrench](https://github.com/TomAFrench) **Created:** 7/27/2022 **Status:** ❌ Closed **Base:** `master` ← **Head:** `remove-32bit-limit-on-amounts` --- ### 📝 Commits (10+) - [`21f3199`](https://github.com/actualbudget/actual/commit/21f31996934fca80fb8444319cf2d7e93f1aa577) fix: use integer check which doesn't require value to be 32 bit - [`2f2e69a`](https://github.com/actualbudget/actual/commit/2f2e69a4c62a3026e37207072c1e12aa3592f8ec) fix: use 64bit compatible integer check in aql compiler - [`a95f9ea`](https://github.com/actualbudget/actual/commit/a95f9ea56b4e4a6ed33df4a9ddc8d5fd053a9d37) fix: replace custom isInteger function with Number.isInteger - [`74f797f`](https://github.com/actualbudget/actual/commit/74f797ffdee3c49c4550c6700154f1838407e9b6) fix: use Math.round in place of truncating digits - [`d69a897`](https://github.com/actualbudget/actual/commit/d69a897a5e9fd365a50985d2b497e797a9ecc9a9) fix: use Math.round in place of truncating digits - [`5281623`](https://github.com/actualbudget/actual/commit/5281623e2f968c3a3d915a8cd64167555b719757) fix: remove unnecessary conversion to 32 bit - [`8d6ae15`](https://github.com/actualbudget/actual/commit/8d6ae15a212f03015d4fd2ab94ab1370646f88f7) fix: replace last usages of | 0 - [`df19183`](https://github.com/actualbudget/actual/commit/df1918377a72712efc248f0d01b7b962e36c6bcb) feat: add explicit value checking on saving to / reading from budget - [`30ca82c`](https://github.com/actualbudget/actual/commit/30ca82cd8ed764b8ba45d17d34352b5b33135cac) Move `safeNumber` to shared util and tweak implementation - [`6b8c6e2`](https://github.com/actualbudget/actual/commit/6b8c6e2dbcbdceebc41d1b57c9c20f6c0b97bb44) Update packages/loot-core/src/mocks/index.js ### 📊 Changes **22 files changed** (+97 additions, -71 deletions) <details> <summary>View changed files</summary> 📝 `packages/api/utils.js` (+1 -1) 📝 `packages/desktop-electron/index.js` (+2 -2) 📝 `packages/loot-core/bin/profile-sql.js` (+7 -7) 📝 `packages/loot-core/src/client/queries.js` (+1 -5) 📝 `packages/loot-core/src/client/query-helpers.test.js` (+1 -1) 📝 `packages/loot-core/src/mocks/budget.js` (+6 -6) 📝 `packages/loot-core/src/mocks/index.js` (+4 -4) 📝 `packages/loot-core/src/server/aql/compiler.js` (+1 -1) 📝 `packages/loot-core/src/server/aql/schema-helpers.js` (+1 -1) 📝 `packages/loot-core/src/server/aql/schema/executors.test.js` (+1 -1) 📝 `packages/loot-core/src/server/budget/actions.js` (+4 -5) 📝 `packages/loot-core/src/server/budget/report.js` (+9 -8) 📝 `packages/loot-core/src/server/budget/rollover.js` (+19 -15) 📝 `packages/loot-core/src/server/budget/util.js` (+6 -3) 📝 `packages/loot-core/src/server/crdt/merkle.js` (+1 -1) 📝 `packages/loot-core/src/server/db/sort.js` (+1 -1) 📝 `packages/loot-core/src/server/sync/sync.property.test.js` (+1 -1) 📝 `packages/loot-core/src/shared/rules.js` (+1 -1) 📝 `packages/loot-core/src/shared/schedules.js` (+1 -1) 📝 `packages/loot-core/src/shared/util.js` (+26 -3) _...and 2 more files_ </details> ### 📄 Description We currently prevent any values greater than 21,474,836.47 ( (2^31 - 1) / 100 ) from being written to the database as a side effect of how we check that the value is an integer. While this is unlikely to cause issues for GBP/USD/EUR users (I'd _love_ to run into this issue myself), it does impact users who use currencies where the unit value is lower for example INR as it manifests at ~250k USD. One user in the discord is encountering this with IDR which means they run into this bug when dealing with values of ~1.4k USD. ``` 2147483647 | 0 == 2147483647 2147483648 | 0 == -2147483648 ``` This is due to the fact we're performing a bitwise operation as `value` is being converted into a signed 32 bit number and back again, causing the overflow. I've replaced this with a non-bitwise integer check so that we support 64 bit numbers. --- Tested by adding a huge value transaction to a fresh account: Before: ![image](https://user-images.githubusercontent.com/15848336/181356630-9667eb03-10ae-47ec-9832-5bc15b664d0b.png) After: ![image](https://user-images.githubusercontent.com/15848336/181355829-66450eac-237f-4ad2-b42d-bc78392019b3.png) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-02-28 20:35:27 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#3041