fix(malachite-app): harden response capacity check with safe arithmetic in GetDecidedValues - #390
Open
forumevi wants to merge 1 commit into
Open
fix(malachite-app): harden response capacity check with safe arithmetic in GetDecidedValues#390forumevi wants to merge 1 commit into
forumevi wants to merge 1 commit into
Conversation
…hecked_sub in get_decided_values
forumevi
requested review from
ZhiyuCircle,
ancazamfir,
romac and
sergio-mena
as code owners
September 12, 2026 14:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces manual arithmetic logic and
#[allow(clippy::arithmetic_side_effects)]suppression inGetDecidedValueshandler with idiomatic, bounds-checked arithmetic (checked_sub+map_or).Context & Motivation
In
crates/malachite-app/src/handlers/get_decided_values.rs, the response size evaluation relied on raw subtraction guarded by conditional short-circuiting:#[allow(clippy::arithmetic_side_effects)]if raw_bytes_len > max_response_size || total_bytes.as_u64() > max_response_size.as_u64() - raw_bytes_len.as_u64()While designed to prevent underflow, relying on manual suppression of Clippy arithmetic warnings introduces unnecessary maintenance risks and potential edge-case arithmetic panics during boundary value conversions.
Solution
as_u64().checked_sub(...).map_or(true, ...)to gracefully handle non-sufficient remaining capacity without triggering unchecked subtraction.#[allow(clippy::arithmetic_side_effects)]attribute, aligning the handler with strict production resilience standards.Testing
cargo test -p malachite-app --lib) — 400/400 tests passing.