Skip to content

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

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

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.

@ZhiyuCircle

Copy link
Copy Markdown
Contributor

Hi @forumevi,

Thank you for your interest in contributing to Arc Node, and apologies for the delay in getting back to this PR.

We're closing out the pull request backlog that predates our current contribution policy. This PR is being closed because it does not reference a GitHub issue. All PRs must reference an existing issue using the format Closes: #XXX, and the author must be assigned to that issue before the PR is opened.

This is not a judgement on the change itself. If you'd still like to land it:

  1. Open an issue describing the problem, or find the existing one
  2. Comment on the issue requesting assignment, and wait for maintainer approval
  3. Open a fresh PR once you have been assigned

Please see CONTRIBUTING.md for details. Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants