Skip to content

fix(pawnio): cap broker SMBus batch delay#74

Merged
hyperb1iss merged 2 commits into
mainfrom
codex/fix-unbounded-delays-in-smbus-broker
May 19, 2026
Merged

fix(pawnio): cap broker SMBus batch delay#74
hyperb1iss merged 2 commits into
mainfrom
codex/fix-unbounded-delays-in-smbus-broker

Conversation

@hyperb1iss
Copy link
Copy Markdown
Owner

@hyperb1iss hyperb1iss commented May 19, 2026

Motivation

  • The broker accepted unbounded Delay { duration_ms } operations in SmBusXferBatch and executed thread::sleep while holding the global buses mutex, allowing a local interactive process to block broker worker threads and cause an availability DoS.

Description

  • Add a broker-side cap MAX_BATCH_DELAY_MS = 1_000 and validate incoming batch delays with a new validate_batch_delay_ms helper.
  • Reject oversized delays early by returning PawnIoError::InvalidInput instead of sleeping for the supplied duration inside BrokerState::smbus_xfer_batch.
  • Preserve existing behavior for valid delays by still performing thread::sleep for values at-or-below the cap.
  • Add a unit test batch_delay_rejects_values_above_maximum to assert that values above the cap are rejected.

Testing

  • Ran cargo test -p hypercolor-windows-pawnio --lib and the crate built and tested successfully in this environment (test runner completed with no failing tests).
  • The added unit test validates the delay validation helper and was exercised by the test run (no test failures).

Codex Task

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Batch operations with delays exceeding the maximum allowed duration are now rejected with an error.
  • Tests

    • Added validation test for batch delay constraints.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 88ee50a5-8f35-4656-9d14-0a127fb5f966

📥 Commits

Reviewing files that changed from the base of the PR and between 7547799 and c55bcb0.

📒 Files selected for processing (1)
  • crates/hypercolor-windows-pawnio/src/windows/broker.rs

📝 Walkthrough

Walkthrough

This PR adds input validation to SMBus batch delay operations by introducing a maximum delay duration constant and validation function. The validation is integrated into batch execution to reject oversized delays, and unit tests verify the rejection behavior.

Changes

Batch Delay Validation

Layer / File(s) Summary
Batch delay validation constant and function
crates/hypercolor-windows-pawnio/src/windows/broker.rs
MAX_BATCH_DELAY_MS constant defines the upper bound, and validate_batch_delay_ms returns PawnIoError::InvalidInput when duration_ms exceeds the maximum.
Batch execution integration
crates/hypercolor-windows-pawnio/src/windows/broker.rs
Batch Delay operation handler calls validate_batch_delay_ms before performing thread::sleep, enforcing the constraint at the execution point.
Delay validation tests
crates/hypercolor-windows-pawnio/src/windows/broker.rs
Test module imports MAX_BATCH_DELAY_MS and new unit test batch_delay_rejects_values_above_maximum verifies validation rejects delays above the maximum.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A bunny checks batch delays with care,
Setting a maximum duration bound fair,
When sleeps run too long, we say "nay!"—
Validation ensures they obey the way! 🕐

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-unbounded-delays-in-smbus-broker

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

hyperb1iss and others added 2 commits May 19, 2026 02:29
The Delay batch op already carries a u64 duration, so u64::from on it
is a useless conversion that trips clippy on Windows targets. Format
the batch-delay validation to satisfy cargo fmt as well.
@hyperb1iss hyperb1iss force-pushed the codex/fix-unbounded-delays-in-smbus-broker branch from b1be1dd to c55bcb0 Compare May 19, 2026 09:34
@hyperb1iss hyperb1iss merged commit 1ed156a into main May 19, 2026
@hyperb1iss hyperb1iss deleted the codex/fix-unbounded-delays-in-smbus-broker branch May 19, 2026 09:34
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.

1 participant