Skip to content

docs(protocol): MAX_MESSAGE_SIZE derivation + compile-time guards (#240) - #287

Merged
alpergundogdu merged 2 commits into
mainfrom
fix/240-max-message-size-guardrails
Apr 22, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
fix/240-max-message-size-guardrails

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

  • Expands the doc comment on MAX_MESSAGE_SIZE to cite ADR 013's derivation (pre-allocation DoS bound, documented per-ALPN message upper bounds, QUIC MAX_STREAMS interaction).
  • Adds two const _: () = assert!(...) guardrails: floor at 64 KiB, ceiling at 16 MiB. An accidental edit to the constant fails the build with a message pointing back to ADR 013.
  • Single file touched: crates/protocol/src/framing.rs. ~25 LOC, no behavior change.

Closes #240.

Why

ADR 013 §Wire Framing pins this constant at 16 MiB but the previous two-line doc didn't record the rationale, and nothing in the tree caught accidental edits. A compile-time assertion is the cheapest durable guard — no runtime cost, no test framework, fires at build time with a message that tells the changer what to read.

Base branch

Based on top of chore/bump-rustls-webpki-rustsec-2026-0104 (PR #286) so cargo deny check advisories passes locally and in CI. Will rebase onto main once #286 merges; merge order is #286 → this.

Test plan

  • cargo clippy -p decdn-protocol --all-targets -- -D warnings → clean
  • cargo test -p decdn-protocol → 22 passed
  • cargo fmt -- --check crates/protocol/src/framing.rs → clean
  • Pre-commit (fmt/clippy/deny) → all passed
  • Manual sanity: tweaked MAX_MESSAGE_SIZE to 32 KiB locally; build failed with the floor message, as designed. Reverted.

🤖 Generated with Claude Code

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates several dependencies in Cargo.lock, including a version bump for windows-sys and rustls-webpki, and introduces detailed documentation and compile-time assertions for MAX_MESSAGE_SIZE in the protocol framing logic. Review feedback identifies a potential issue where forcing windows-sys to version 0.59.0 in the lockfile may violate semver constraints of dependent crates. Furthermore, it is recommended to change the range-based assertions for MAX_MESSAGE_SIZE to an exact equality check to strictly enforce the 16 MiB limit defined in ADR 013.

Comment thread Cargo.lock Outdated
dependencies = [
"libc",
"windows-sys 0.52.0",
"windows-sys 0.59.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The update of windows-sys from 0.52.0 to 0.59.0 for several crates (e.g., errno, quinn-udp, rustix) appears to be an incorrect lockfile modification. These crates are locked to the 0.52 series in their respective Cargo.toml files. Forcing them to 0.59.0 in Cargo.lock without updating the crates themselves is a semver violation for 0.x versions and will likely cause cargo to error out or re-resolve the lockfile during the next build. If a unification of windows-sys versions was intended, it should be achieved by updating the dependent crates to versions that officially support 0.59.0.

Comment thread crates/protocol/src/framing.rs Resolved
alpergundogdu added a commit that referenced this pull request Apr 22, 2026
Per review on #287: ADR 013 §Wire Framing pins the value at 16 MiB, not
a range. A shrink is equally a protocol-wide change (breaks peers whose
messages fit the old cap), so the guard should catch any edit in either
direction. Collapse the floor+ceiling pair into one equality assert and
note in the doc that per-deployment tightening is a runtime-config
concern, not a constant edit.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Addressed the two review comments:

Medium — MAX_MESSAGE_SIZE range vs. equality (fff3235): adopted the suggestion. Collapsed the two range asserts into one equality check — a shrink is just as much a wire-compat change as a bump, so catching both with a single guard is cleaner. The doc comment now explicitly says any edit requires an ADR amendment and that per-deployment tightening (for memory-constrained operators) is a runtime-config concern, not a change to the constant.

High — Cargo.lock windows-sys drift: out of scope for this PR. The 0.52 → 0.59 entries come from commit b6d35ad (merged PR #262, dependabot's rust-dependencies group update) which is already on main. This PR is based on top of chore/bump-rustls-webpki-rustsec-2026-0104 (PR #286) which itself sits on b6d35ad. When GitHub compares this PR against a main that has PR #262 merged, those lines don't actually appear in the merge diff. Nothing to fix here.

alpergundogdu and others added 2 commits April 22, 2026 16:03
#240)

ADR 013 pins the 16 MiB ceiling (pre-allocation DoS bound vs. documented
per-ALPN message upper bounds), but the doc comment didn't say so and
nothing caught accidental edits. Expand the comment to cite the
derivation and add two `const _: () = assert!(...)` guardrails so a
shrink below 64 KiB or a bump above 16 MiB fails the build with a
pointer back to the ADR.

Closes #240.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Per review on #287: ADR 013 §Wire Framing pins the value at 16 MiB, not
a range. A shrink is equally a protocol-wide change (breaks peers whose
messages fit the old cap), so the guard should catch any edit in either
direction. Collapse the floor+ceiling pair into one equality assert and
note in the doc that per-deployment tightening is a runtime-config
concern, not a constant edit.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alpergundogdu
alpergundogdu force-pushed the fix/240-max-message-size-guardrails branch from fff3235 to 0e90ca0 Compare April 22, 2026 15:03
@alpergundogdu
alpergundogdu merged commit 482e8d8 into main Apr 22, 2026
9 checks passed
@alpergundogdu
alpergundogdu deleted the fix/240-max-message-size-guardrails branch April 22, 2026 15:13
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.

MAX_MESSAGE_SIZE constant is not documented or enforced with a compile-time assertion against protocol limits

1 participant