Skip to content

fix(command): validate command_buffer_size against its maximum, and clamp the channel's initial buffer - #1422

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/channel-buffer-size-validation
Sep 22, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/channel-buffer-size-validation

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Channel::new took buffer_size and max_buffer_size and stored both without ever comparing them, so
front_buf could start already larger than the cap it must respect — and
try_read_delimited_message tripped its own debug_assert! ("front buffer capacity must never exceed
max_buffer_size") on the very first parse, before any wire data was examined.

It is reachable from configuration: command_buffer_size and max_command_buffer_size were
independent options with no cross-validation, so an operator's TOML produced the same state on the real
master↔worker channel. Debug, test and fuzz builds panic; release builds compile the assertion out and
run with a buffer violating the bound the growth logic reasons about.

Validated at both ends, and for different reasons

At config load: reject, do not clamp. A command_buffer_size above its own maximum is a mistake
rather than an intent, and silently rewriting it hides the mistake from the operator. The new
ConfigError::CommandBufferSizeExceedsMax names both keys and both values and says which to change:

command_buffer_size = X exceeds max_command_buffer_size = Y:
lower command_buffer_size to <= Y or raise max_command_buffer_size to >= X

It sits immediately after the sibling BufferSizeTooSmallForH2 check and follows its shape. The guard
is strict-greater, so equal values still load — pinned by a boundary test.

At Channel::new: clamp, with a warn!. Config validation protects the configured path; it does
nothing for a direct caller. initial_buffer_size becomes min(buffer_size, max_buffer_size), logged
when it fires, with a post-condition debug_assert! restating the invariant at construction so a
violation surfaces there rather than at the next parse.

Why clamp rather than a fallible constructor — and why this is not #1418 again

There is an open issue, #1418, saying H2FloodConfig::new's .max(1) clamp has no production
caller
: its fields are pub, and lib/src/http.rs and https.rs build it by raw struct literal,
bypassing the constructor entirely. A validating constructor nothing calls is worse than no
constructor, so that failure mode had to be ruled out rather than assumed avoided.

Channel is structurally different, and a review verified it by enumeration rather than taking the
claim:

  • initial_buffer_size and max_buffer_size are private, no Default derive, no Clone.
  • The only two Channel { ... } struct literals in the repository are both inside channel.rs:
    new(), and into() — which merely moves the caller's already-clamped values and cannot introduce
    fresh ones.
  • Every construction site across bin/, command/, e2e/, lib/ and the examples resolves to
    new(), from_path() (which calls new), or generate/generate_nonblocking (each of which calls
    new twice). None can reach the fields.

So the clamp is not merely the intended path — it is the only one. A fallible constructor would force
roughly twenty call sites, several with hardcoded-valid literals, to handle an error unreachable for
any of them.

One structural note the review raised, worth stating rather than burying

Config itself has pub fields and derives Default, so its validation is convention-enforced rather
than type-enforced: nothing in the type system stops a future caller building one directly and skipping
ConfigBuilder::into_config. No such bypass exists today — every Config { literal was enumerated and
the worker fork path only forwards the already-validated master values.

That asymmetry is precisely why the channel-side clamp earns its keep as defence in depth rather than
being redundant with the config check.

Tests, both seen red

Config: loading a configuration with command_buffer_size = 2_000_000 and
max_command_buffer_size = 1_000_000 succeeded before, returning a Config with both values intact.
After, it fails with the specific error — the test asserts the variant, not merely that loading failed.
A sibling test pins that equal values still load.

Constructor: Channel::generate_nonblocking(45, 32) — the exact pair a fuzz harness produced —
then parsing:

thread '...' panicked at command/src/channel.rs:556:9:
front buffer capacity must never exceed max_buffer_size

green after the clamp. A review reproduced this independently, and checked that the new
construction-time assertion does not paper over the pre-existing parse-time one: with only the min()
reverted, the new assert fires first and fails faster; with both reverted, the original assert fires
exactly as before. Two layered guards, neither masking the other.

The production diff was grepped for literals shared with the test files; there are none, since both
changes are pure comparisons.

Knock-on

The fuzz target in #1420 clamps its own construction generator to buffer_size <= max_buffer_size
specifically to work around this defect, with a note saying the clamp should be revisited once this
lands. It becomes removable: Channel::new now clamps internally, so an inverted pair from the
generator can no longer violate the invariant, and removing the harness clamp would additionally
exercise the new clamp-and-warn path. That is #1420's call; fuzz/ is untouched here.

Not fixed here

doc/configure_admin_ops.md §5.2 says the wire-length bound is command_buffer_size when the code
checks max_buffer_size. Confirmed pre-existing and unrelated to this fix; filed as #1421 rather
than left silent.

Validation, both feature shapes

cargo +1.93.1 build --all-features --locked                       -> exit 0
cargo +1.93.1 build --locked                                      -> exit 0
cargo +1.93.1 clippy --all-targets --all-features -- -D warnings  -> exit 0
cargo +1.93.1 clippy --all-targets --locked -- -D warnings        -> exit 0
cargo +nightly fmt --all -- --check                               -> exit 0
cargo +1.93.1 test -p sozu-command-lib --locked                   -> 161 passed, 0 failed
cargo +1.93.1 test -p sozu --locked                               -> 104 passed, 0 failed
python3 .github/scripts/check_doc_citations.py --base origin/main -> exit 0

Closes #1416.

@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/channel-buffer-size-validation branch from 0ac27fc to 8e326b3 Compare September 22, 2026 10:24
FlorentinDUBOIS added a commit that referenced this pull request Sep 22, 2026
…h bound

`doc/configure_admin_ops.md` §5.2 told an operator the command channel
rejects a peer-declared `message_len` exceeding `command_buffer_size`,
"default `16384`". Both halves were wrong.

`Channel::try_read_delimited_message` (`command/src/channel.rs`) compares
`message_len` against the channel's `max_buffer_size` field, and
`Channel::write_delimited_message` bounds an outgoing frame against the
same field. Every production construction site —
`bin/src/command/server.rs`, `bin/src/worker.rs`, `bin/src/ctl/mod.rs`,
`bin/src/upgrade.rs` — fills that field from `max_command_buffer_size`,
never from `command_buffer_size`. No other construction site is evidence
about the shipped bound: the unit tests in `command/src/channel.rs`,
`lib/src/http.rs`, `lib/src/server.rs` and `lib/src/tcp.rs`, and all
three example programs under `lib/examples/` (`http.rs`, `https.rs`,
`tcp.rs`), pass literal sizes; the end-to-end harness
(`Worker::create_server` and `Worker::spawn_worker` in
`e2e/src/sozu/worker.rs`) does build its channels from
`command_buffer_size` and `max_command_buffer_size`, but from a
configuration the test run assembles rather than a deployed one.
`grep -rn 'Channel::new\|Channel::generate' --include='*.rs' .`
enumerates every site. And `16384` is not a default: it is what three of
the four configuration files shipped here override to,
`os-build/config.toml` using `163_840`. The built-in defaults are
`DEFAULT_COMMAND_BUFFER_SIZE` = `1_000_000` and
`DEFAULT_MAX_COMMAND_BUFFER_SIZE` = `2_000_000` (`command/src/config.rs`).

Under the defaults the document understated the accepted bound by a
factor of two, and an operator tightening the bound against a hostile
peer was pointed at the knob that does not set it. §5.2 now names
`max_command_buffer_size`, tabulates what each key controls with its real
default, and states that lowering `command_buffer_size` tightens nothing.
The `command_buffer_size` row is scoped rather than absolute: it sizes
the supervisor↔worker and CLI channels, but `CommandHub::register_client`
(`bin/src/command/server.rs`) allocates the command-socket client channel
at a hardcoded `4096` and takes only its ceiling from configuration.

Three more instances of the same class, found by sweeping both key names
across the tree:

- `bin/config.toml` and `os-build/config.toml` annotated
  `max_command_buffer_size` as "defaults to `command_buffer_size * 2`".
  The TOML path resolves an omitted value to the flat
  `DEFAULT_MAX_COMMAND_BUFFER_SIZE` = `2_000_000` in `ConfigBuilder::new`
  (`command/src/config.rs`), independently of `command_buffer_size`;
  `ConfigBuilder::into_config` populates listeners and clusters and
  validates the TCP SNI/ALPN invariants, and resolves no buffer default.
  The doubling lives only in `resolve_max_command_buffer_size`
  (`bin/src/main.rs`), serving the internal `worker` / `main` re-exec
  subcommands its own doc comment calls "never operator-facing".
- `doc/protocol.md` gave the ceiling as "2 MiB" twice. `2_000_000` bytes
  is 2 MB, which is how `command/src/config.rs` and
  `bin/src/command/server.rs` already describe it.
- §5.2, `doc/protocol.md`, `bin/config.toml` and `os-build/config.toml`
  all asserted that an over-cap frame ends the connection — §5.2 that
  the supervisor "logs and drops the offending peer's session". It does
  not. `try_read_delimited_message` returns
  `ChannelError::MessageTooLarge`, `extract_messages`
  (`bin/src/command/sessions.rs`) discards every read error without
  logging it, `ClientSession::ready` then returns
  `ClientResult::NothingToDo`, and `WorkerSession::ready` returns
  `CloseSession` only for `is_error()`/`is_hup()` readiness, which a
  parse error never sets. The four sites no longer state a behaviour the
  code does not have; naming what does happen is left to #1428, which
  tracks the defect.

Deliberately deferred to #1428 rather than fixed here: the comment at
`command/src/channel.rs:551` still says the rejection is raised "so the
read loop disconnects cleanly", which is false for exactly the reason
the four sites above were corrected. It is a code comment in a
`docs(command)` changeset, and it names neither key, so the two-key
sweep that found the other instances could not have reached it. #1428's
body already quotes it. Recording it here rather than passing over it in
silence, because leaving it beside corrected text would otherwise read
as having been checked.

§5.2 cites `try_read_delimited_message` by symbol rather than by line so
the text survives #1422, whose `Channel::new` doc comment
shifts the rest of `channel.rs` by 33 lines. That branch also adds
`ConfigError::CommandBufferSizeExceedsMax` (`command/src/config.rs`),
which rejects `command_buffer_size > max_command_buffer_size` at config
load, and clamps `Channel::new`'s initial capacity to `max_buffer_size`;
its pull request carries `Closes #1416`. So §5.2 states the
`command_buffer_size` <= `max_command_buffer_size` requirement and the
reason for it — the first is the capacity a channel buffer is configured
to start at and shrink back to, the second the ceiling it may never grow
past — and asserts neither the state an inverted pair would produce, nor
any handling of one, nor that any issue is open. It reads identically
before and after #1422 lands.

`git merge-tree --write-tree HEAD refs/heads/fix/channel-buffer-size-validation`
(#1422 head `0ac27fc1`) exits 1 with `CONFLICT (content): Merge conflict
in CHANGELOG.md`, both branches inserting a `### 🐛 Fixed` heading at the
same anchor. The four documentation and configuration files edited here
are not reconciled at all: #1422 touches none of them, so there is no
merge to be clean or unclean. `git diff origin/main
refs/heads/fix/channel-buffer-size-validation --name-only` lists only
`CHANGELOG.md`, `command/src/channel.rs`, `command/src/config.rs`,
`doc/configure.md` and `doc/lifetime_of_a_session.md`.

Closes #1421.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Sep 22, 2026
…h bound

`doc/configure_admin_ops.md` §5.2 told an operator the command channel
rejects a peer-declared `message_len` exceeding `command_buffer_size`,
"default `16384`". Both halves were wrong.

`Channel::try_read_delimited_message` (`command/src/channel.rs`) compares
`message_len` against the channel's `max_buffer_size` field, and
`Channel::write_delimited_message` bounds an outgoing frame against the
same field. Every production construction site —
`bin/src/command/server.rs`, `bin/src/worker.rs`, `bin/src/ctl/mod.rs`,
`bin/src/upgrade.rs` — fills that field from `max_command_buffer_size`,
never from `command_buffer_size`. No other construction site is evidence
about the shipped bound: the unit tests in `command/src/channel.rs`,
`lib/src/http.rs`, `lib/src/server.rs` and `lib/src/tcp.rs`, and all
three example programs under `lib/examples/` (`http.rs`, `https.rs`,
`tcp.rs`), pass literal sizes; the end-to-end harness
(`Worker::create_server` and `Worker::spawn_worker` in
`e2e/src/sozu/worker.rs`) does build its channels from
`command_buffer_size` and `max_command_buffer_size`, but from a
configuration the test run assembles rather than a deployed one.
`grep -rn 'Channel::new\|Channel::generate' --include='*.rs' .`
enumerates every site. And `16384` is not a default: it is what three of
the four configuration files shipped here override to,
`os-build/config.toml` using `163_840`. The built-in defaults are
`DEFAULT_COMMAND_BUFFER_SIZE` = `1_000_000` and
`DEFAULT_MAX_COMMAND_BUFFER_SIZE` = `2_000_000` (`command/src/config.rs`).

Under the defaults the document understated the accepted bound by a
factor of two, and an operator tightening the bound against a hostile
peer was pointed at the knob that does not set it. §5.2 now names
`max_command_buffer_size`, tabulates what each key controls with its real
default, and states that lowering `command_buffer_size` tightens nothing.
The `command_buffer_size` row is scoped rather than absolute: it sizes
the supervisor↔worker and CLI channels, but `CommandHub::register_client`
(`bin/src/command/server.rs`) allocates the command-socket client channel
at a hardcoded `4096` and takes only its ceiling from configuration.

Three more instances of the same class, found by sweeping both key names
across the tree:

- `bin/config.toml` and `os-build/config.toml` annotated
  `max_command_buffer_size` as "defaults to `command_buffer_size * 2`".
  The TOML path resolves an omitted value to the flat
  `DEFAULT_MAX_COMMAND_BUFFER_SIZE` = `2_000_000` in `ConfigBuilder::new`
  (`command/src/config.rs`), independently of `command_buffer_size`;
  `ConfigBuilder::into_config` populates listeners and clusters and
  validates the TCP SNI/ALPN invariants, and resolves no buffer default.
  The doubling lives only in `resolve_max_command_buffer_size`
  (`bin/src/main.rs`), serving the internal `worker` / `main` re-exec
  subcommands its own doc comment calls "never operator-facing".
- `doc/protocol.md` gave the ceiling as "2 MiB" twice. `2_000_000` bytes
  is 2 MB, which is how `command/src/config.rs` and
  `bin/src/command/server.rs` already describe it.
- §5.2, `doc/protocol.md`, `bin/config.toml` and `os-build/config.toml`
  all asserted that an over-cap frame ends the connection — §5.2 that
  the supervisor "logs and drops the offending peer's session". It does
  not. `try_read_delimited_message` returns
  `ChannelError::MessageTooLarge`, `extract_messages`
  (`bin/src/command/sessions.rs`) discards every read error without
  logging it, `ClientSession::ready` then returns
  `ClientResult::NothingToDo`, and `WorkerSession::ready` returns
  `CloseSession` only for `is_error()`/`is_hup()` readiness, which a
  parse error never sets. The four sites no longer state a behaviour the
  code does not have; naming what does happen is left to #1428, which
  tracks the defect.

Deliberately deferred to #1428 rather than fixed here: the comment at
`command/src/channel.rs:551` still says the rejection is raised "so the
read loop disconnects cleanly", which is false for exactly the reason
the four sites above were corrected. It is a code comment in a
`docs(command)` changeset, and it names neither key, so the two-key
sweep that found the other instances could not have reached it. #1428's
body already quotes it. Recording it here rather than passing over it in
silence, because leaving it beside corrected text would otherwise read
as having been checked.

§5.2 cites `try_read_delimited_message` by symbol rather than by line so
the text survives #1422, whose `Channel::new` doc comment
shifts the rest of `channel.rs` by 33 lines. That branch also adds
`ConfigError::CommandBufferSizeExceedsMax` (`command/src/config.rs`),
which rejects `command_buffer_size > max_command_buffer_size` at config
load, and clamps `Channel::new`'s initial capacity to `max_buffer_size`;
its pull request carries `Closes #1416`. So §5.2 states the
`command_buffer_size` <= `max_command_buffer_size` requirement and the
reason for it — the first is the capacity a channel buffer is configured
to start at and shrink back to, the second the ceiling it may never grow
past — and asserts neither the state an inverted pair would produce, nor
any handling of one, nor that any issue is open. It reads identically
before and after #1422 lands.

`git merge-tree --write-tree HEAD refs/heads/fix/channel-buffer-size-validation`
(#1422 head `0ac27fc1`) exits 1 with `CONFLICT (content): Merge conflict
in CHANGELOG.md`, both branches inserting a `### 🐛 Fixed` heading at the
same anchor. The four documentation and configuration files edited here
are not reconciled at all: #1422 touches none of them, so there is no
merge to be clean or unclean. `git diff origin/main
refs/heads/fix/channel-buffer-size-validation --name-only` lists only
`CHANGELOG.md`, `command/src/channel.rs`, `command/src/config.rs`,
`doc/configure.md` and `doc/lifetime_of_a_session.md`.

Closes #1421.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Sep 22, 2026
…h bound

`doc/configure_admin_ops.md` §5.2 told an operator the command channel
rejects a peer-declared `message_len` exceeding `command_buffer_size`,
"default `16384`". Both halves were wrong.

`Channel::try_read_delimited_message` (`command/src/channel.rs`) compares
`message_len` against the channel's `max_buffer_size` field, and
`Channel::write_delimited_message` bounds an outgoing frame against the
same field. Every production construction site —
`bin/src/command/server.rs`, `bin/src/worker.rs`, `bin/src/ctl/mod.rs`,
`bin/src/upgrade.rs` — fills that field from `max_command_buffer_size`,
never from `command_buffer_size`. No other construction site is evidence
about the shipped bound: the unit tests in `command/src/channel.rs`,
`lib/src/http.rs`, `lib/src/server.rs` and `lib/src/tcp.rs`, and all
three example programs under `lib/examples/` (`http.rs`, `https.rs`,
`tcp.rs`), pass literal sizes; the end-to-end harness
(`Worker::create_server` and `Worker::spawn_worker` in
`e2e/src/sozu/worker.rs`) does build its channels from
`command_buffer_size` and `max_command_buffer_size`, but from a
configuration the test run assembles rather than a deployed one.
`grep -rn 'Channel::new\|Channel::generate' --include='*.rs' .`
enumerates every site. And `16384` is not a default: it is what three of
the four configuration files shipped here override to,
`os-build/config.toml` using `163_840`. The built-in defaults are
`DEFAULT_COMMAND_BUFFER_SIZE` = `1_000_000` and
`DEFAULT_MAX_COMMAND_BUFFER_SIZE` = `2_000_000` (`command/src/config.rs`).

Under the defaults the document understated the accepted bound by a
factor of two, and an operator tightening the bound against a hostile
peer was pointed at the knob that does not set it. §5.2 now names
`max_command_buffer_size`, tabulates what each key controls with its real
default, and states that lowering `command_buffer_size` tightens nothing.
The `command_buffer_size` row is scoped rather than absolute: it sizes
the supervisor↔worker and CLI channels, but `CommandHub::register_client`
(`bin/src/command/server.rs`) allocates the command-socket client channel
at a hardcoded `4096` and takes only its ceiling from configuration.

Three more instances of the same class, found by sweeping both key names
across the tree:

- `bin/config.toml` and `os-build/config.toml` annotated
  `max_command_buffer_size` as "defaults to `command_buffer_size * 2`".
  The TOML path resolves an omitted value to the flat
  `DEFAULT_MAX_COMMAND_BUFFER_SIZE` = `2_000_000` in `ConfigBuilder::new`
  (`command/src/config.rs`), independently of `command_buffer_size`;
  `ConfigBuilder::into_config` populates listeners and clusters and
  validates the TCP SNI/ALPN invariants, and resolves no buffer default.
  The doubling lives only in `resolve_max_command_buffer_size`
  (`bin/src/main.rs`), serving the internal `worker` / `main` re-exec
  subcommands its own doc comment calls "never operator-facing".
- `doc/protocol.md` gave the ceiling as "2 MiB" twice. `2_000_000` bytes
  is 2 MB, which is how `command/src/config.rs` and
  `bin/src/command/server.rs` already describe it.
- §5.2, `doc/protocol.md`, `bin/config.toml` and `os-build/config.toml`
  all asserted that an over-cap frame ends the connection — §5.2 that
  the supervisor "logs and drops the offending peer's session". It does
  not. `try_read_delimited_message` returns
  `ChannelError::MessageTooLarge`, `extract_messages`
  (`bin/src/command/sessions.rs`) discards every read error without
  logging it, `ClientSession::ready` then returns
  `ClientResult::NothingToDo`, and `WorkerSession::ready` returns
  `CloseSession` only for `is_error()`/`is_hup()` readiness, which a
  parse error never sets. The four sites no longer state a behaviour the
  code does not have; naming what does happen is left to #1428, which
  tracks the defect.

Deliberately deferred to #1428 rather than fixed here: the comment at
`command/src/channel.rs:551` still says the rejection is raised "so the
read loop disconnects cleanly", which is false for exactly the reason
the four sites above were corrected. It is a code comment in a
`docs(command)` changeset, and it names neither key, so the two-key
sweep that found the other instances could not have reached it. #1428's
body already quotes it. Recording it here rather than passing over it in
silence, because leaving it beside corrected text would otherwise read
as having been checked.

§5.2 cites `try_read_delimited_message` by symbol rather than by line so
the text survives #1422, whose `Channel::new` doc comment
shifts the rest of `channel.rs` by 33 lines. That branch also adds
`ConfigError::CommandBufferSizeExceedsMax` (`command/src/config.rs`),
which rejects `command_buffer_size > max_command_buffer_size` at config
load, and clamps `Channel::new`'s initial capacity to `max_buffer_size`;
its pull request carries `Closes #1416`. So §5.2 states the
`command_buffer_size` <= `max_command_buffer_size` requirement and the
reason for it — the first is the capacity a channel buffer is configured
to start at and shrink back to, the second the ceiling it may never grow
past — and asserts neither the state an inverted pair would produce, nor
any handling of one, nor that any issue is open. It reads identically
before and after #1422 lands.

`git merge-tree --write-tree HEAD refs/heads/fix/channel-buffer-size-validation`
(#1422 head `0ac27fc1`) exits 1 with `CONFLICT (content): Merge conflict
in CHANGELOG.md`, both branches inserting a `### 🐛 Fixed` heading at the
same anchor. The four documentation and configuration files edited here
are not reconciled at all: #1422 touches none of them, so there is no
merge to be clean or unclean. `git diff origin/main
refs/heads/fix/channel-buffer-size-validation --name-only` lists only
`CHANGELOG.md`, `command/src/channel.rs`, `command/src/config.rs`,
`doc/configure.md` and `doc/lifetime_of_a_session.md`.

Closes #1421.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Sep 22, 2026
…h bound (#1435)

`doc/configure_admin_ops.md` §5.2 told an operator the command channel
rejects a peer-declared `message_len` exceeding `command_buffer_size`,
"default `16384`". Both halves were wrong.

`Channel::try_read_delimited_message` (`command/src/channel.rs`) compares
`message_len` against the channel's `max_buffer_size` field, and
`Channel::write_delimited_message` bounds an outgoing frame against the
same field. Every production construction site —
`bin/src/command/server.rs`, `bin/src/worker.rs`, `bin/src/ctl/mod.rs`,
`bin/src/upgrade.rs` — fills that field from `max_command_buffer_size`,
never from `command_buffer_size`. No other construction site is evidence
about the shipped bound: the unit tests in `command/src/channel.rs`,
`lib/src/http.rs`, `lib/src/server.rs` and `lib/src/tcp.rs`, and all
three example programs under `lib/examples/` (`http.rs`, `https.rs`,
`tcp.rs`), pass literal sizes; the end-to-end harness
(`Worker::create_server` and `Worker::spawn_worker` in
`e2e/src/sozu/worker.rs`) does build its channels from
`command_buffer_size` and `max_command_buffer_size`, but from a
configuration the test run assembles rather than a deployed one.
`grep -rn 'Channel::new\|Channel::generate' --include='*.rs' .`
enumerates every site. And `16384` is not a default: it is what three of
the four configuration files shipped here override to,
`os-build/config.toml` using `163_840`. The built-in defaults are
`DEFAULT_COMMAND_BUFFER_SIZE` = `1_000_000` and
`DEFAULT_MAX_COMMAND_BUFFER_SIZE` = `2_000_000` (`command/src/config.rs`).

Under the defaults the document understated the accepted bound by a
factor of two, and an operator tightening the bound against a hostile
peer was pointed at the knob that does not set it. §5.2 now names
`max_command_buffer_size`, tabulates what each key controls with its real
default, and states that lowering `command_buffer_size` tightens nothing.
The `command_buffer_size` row is scoped rather than absolute: it sizes
the supervisor↔worker and CLI channels, but `CommandHub::register_client`
(`bin/src/command/server.rs`) allocates the command-socket client channel
at a hardcoded `4096` and takes only its ceiling from configuration.

Three more instances of the same class, found by sweeping both key names
across the tree:

- `bin/config.toml` and `os-build/config.toml` annotated
  `max_command_buffer_size` as "defaults to `command_buffer_size * 2`".
  The TOML path resolves an omitted value to the flat
  `DEFAULT_MAX_COMMAND_BUFFER_SIZE` = `2_000_000` in `ConfigBuilder::new`
  (`command/src/config.rs`), independently of `command_buffer_size`;
  `ConfigBuilder::into_config` populates listeners and clusters and
  validates the TCP SNI/ALPN invariants, and resolves no buffer default.
  The doubling lives only in `resolve_max_command_buffer_size`
  (`bin/src/main.rs`), serving the internal `worker` / `main` re-exec
  subcommands its own doc comment calls "never operator-facing".
- `doc/protocol.md` gave the ceiling as "2 MiB" twice. `2_000_000` bytes
  is 2 MB, which is how `command/src/config.rs` and
  `bin/src/command/server.rs` already describe it.
- §5.2, `doc/protocol.md`, `bin/config.toml` and `os-build/config.toml`
  all asserted that an over-cap frame ends the connection — §5.2 that
  the supervisor "logs and drops the offending peer's session". It does
  not. `try_read_delimited_message` returns
  `ChannelError::MessageTooLarge`, `extract_messages`
  (`bin/src/command/sessions.rs`) discards every read error without
  logging it, `ClientSession::ready` then returns
  `ClientResult::NothingToDo`, and `WorkerSession::ready` returns
  `CloseSession` only for `is_error()`/`is_hup()` readiness, which a
  parse error never sets. The four sites no longer state a behaviour the
  code does not have; naming what does happen is left to #1428, which
  tracks the defect.

Deliberately deferred to #1428 rather than fixed here: the comment at
`command/src/channel.rs:551` still says the rejection is raised "so the
read loop disconnects cleanly", which is false for exactly the reason
the four sites above were corrected. It is a code comment in a
`docs(command)` changeset, and it names neither key, so the two-key
sweep that found the other instances could not have reached it. #1428's
body already quotes it. Recording it here rather than passing over it in
silence, because leaving it beside corrected text would otherwise read
as having been checked.

§5.2 cites `try_read_delimited_message` by symbol rather than by line so
the text survives #1422, whose `Channel::new` doc comment
shifts the rest of `channel.rs` by 33 lines. That branch also adds
`ConfigError::CommandBufferSizeExceedsMax` (`command/src/config.rs`),
which rejects `command_buffer_size > max_command_buffer_size` at config
load, and clamps `Channel::new`'s initial capacity to `max_buffer_size`;
its pull request carries `Closes #1416`. So §5.2 states the
`command_buffer_size` <= `max_command_buffer_size` requirement and the
reason for it — the first is the capacity a channel buffer is configured
to start at and shrink back to, the second the ceiling it may never grow
past — and asserts neither the state an inverted pair would produce, nor
any handling of one, nor that any issue is open. It reads identically
before and after #1422 lands.

`git merge-tree --write-tree HEAD refs/heads/fix/channel-buffer-size-validation`
(#1422 head `0ac27fc1`) exits 1 with `CONFLICT (content): Merge conflict
in CHANGELOG.md`, both branches inserting a `### 🐛 Fixed` heading at the
same anchor. The four documentation and configuration files edited here
are not reconciled at all: #1422 touches none of them, so there is no
merge to be clean or unclean. `git diff origin/main
refs/heads/fix/channel-buffer-size-validation --name-only` lists only
`CHANGELOG.md`, `command/src/channel.rs`, `command/src/config.rs`,
`doc/configure.md` and `doc/lifetime_of_a_session.md`.

Closes #1421.

Signed-off-by: Florentin Dubois <[email protected]>
…_buffer_size

Channel::new (command/src/channel.rs) took buffer_size and max_buffer_size
without ever comparing them, so a caller-supplied buffer_size above
max_buffer_size started front_buf/back_buf already larger than the ceiling
every growth/shrink path in the file reasons against. try_read_delimited_message
then tripped its own "front buffer capacity must never exceed max_buffer_size"
debug_assert! on the very first parse, before any wire byte was examined; a
release build ran on with the invariant silently violated.

It was reachable from configuration: command_buffer_size and
max_command_buffer_size were independent command/src/config.rs options with
no cross-validation, so an operator's TOML reached the same state on the real
master<->worker channel.

ConfigBuilder::into_config now rejects the pair with a new
ConfigError::CommandBufferSizeExceedsMax, naming both keys and both values,
before a Channel is ever built. Channel::new additionally clamps buffer_size
to max_buffer_size (logging a warn! when it does) as a structural backstop
for any direct caller that bypasses config validation: unlike
H2FloodConfig::new's clamp (#1418), which production bypasses entirely via a
raw struct literal, Channel::new is the only place a Channel is built (its
buffer-size fields are private), so this clamp cannot be routed around.

Closes #1416

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/channel-buffer-size-validation branch from 8e326b3 to 5d334e7 Compare September 22, 2026 11:52
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 7a223a8 into main Sep 22, 2026
1 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant