Skip to content

fix(malachite-app): harden response capacity check with safe arithmetic in GetDecidedValues - #390

Open
forumevi wants to merge 1 commit into
circlefin:mainfrom
forumevi:fix/core-resilience-audit
Open

fix(malachite-app): harden response capacity check with safe arithmetic in GetDecidedValues#390
forumevi wants to merge 1 commit into
circlefin:mainfrom
forumevi:fix/core-resilience-audit

Conversation

@forumevi

Copy link
Copy Markdown

Summary

This PR replaces manual arithmetic logic and #[allow(clippy::arithmetic_side_effects)] suppression in GetDecidedValues handler 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

  • Refactored the capacity subtraction to use as_u64().checked_sub(...).
  • Leveraged map_or(true, ...) to gracefully handle non-sufficient remaining capacity without triggering unchecked subtraction.
  • Removed the #[allow(clippy::arithmetic_side_effects)] attribute, aligning the handler with strict production resilience standards.

Testing

  • Verified through crate test suite (cargo test -p malachite-app --lib) — 400/400 tests passing.
  • Verified compilation and Clippy adherence with zero warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant