-
Notifications
You must be signed in to change notification settings - Fork 2
chore: remove primary EC check #327
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Check failure
Code scanning / CodeQL
User-controlled data in arithmetic expression High
Copilot Autofix
AI 6 months ago
To fix this issue, we need to ensure that any arithmetic operation involving user-controlled data (here,
notificationFeeAmount) does not result in an overflow or underflow. The best way is to validate the input before performing the arithmetic, ensuring that the result of the addition or subtraction will not exceed the bounds of thelongtype. We should also ensure that the notification fee is not negative, as that would likely be invalid in the business context.Specifically, in
updateAmountsWithNotificationFee, before performing:paymentOption.setAmount(paymentOption.getAmount() + notificationFeeAmount)elem.setAmount(elem.getAmount() + notificationFeeAmount)We should check that the sum will not exceed
Long.MAX_VALUEand will not be less thanLong.MIN_VALUE. Similarly, for subtraction, we should check for underflow. If the check fails, we should throw an exception (e.g.,AppException) indicating invalid input.We will add a helper method to perform safe addition and subtraction with overflow checks, and use it in place of the direct arithmetic. We will also validate that
notificationFeeAmountis non-negative.All changes are within
src/main/java/it/gov/pagopa/debtposition/service/payments/PaymentsService.java.