Repository navigation
fix(command): validate command_buffer_size against its maximum, and clamp the channel's initial buffer - #1422
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 22, 2026 06:38
FlorentinDUBOIS
force-pushed
the
fix/channel-buffer-size-validation
branch
from
September 22, 2026 10:24
0ac27fc to
8e326b3
Compare
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
force-pushed
the
fix/channel-buffer-size-validation
branch
from
September 22, 2026 11:52
8e326b3 to
5d334e7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Channel::newtookbuffer_sizeandmax_buffer_sizeand stored both without ever comparing them, sofront_bufcould start already larger than the cap it must respect — andtry_read_delimited_messagetripped its owndebug_assert!("front buffer capacity must never exceedmax_buffer_size") on the very first parse, before any wire data was examined.
It is reachable from configuration:
command_buffer_sizeandmax_command_buffer_sizewereindependent 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_sizeabove its own maximum is a mistakerather than an intent, and silently rewriting it hides the mistake from the operator. The new
ConfigError::CommandBufferSizeExceedsMaxnames both keys and both values and says which to change:It sits immediately after the sibling
BufferSizeTooSmallForH2check and follows its shape. The guardis strict-greater, so equal values still load — pinned by a boundary test.
At
Channel::new: clamp, with awarn!. Config validation protects the configured path; it doesnothing for a direct caller.
initial_buffer_sizebecomesmin(buffer_size, max_buffer_size), loggedwhen it fires, with a post-condition
debug_assert!restating the invariant at construction so aviolation 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 productioncaller: its fields are
pub, andlib/src/http.rsandhttps.rsbuild 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.
Channelis structurally different, and a review verified it by enumeration rather than taking theclaim:
initial_buffer_sizeandmax_buffer_sizeare private, noDefaultderive, noClone.Channel { ... }struct literals in the repository are both insidechannel.rs:new(), andinto()— which merely moves the caller's already-clamped values and cannot introducefresh ones.
bin/,command/,e2e/,lib/and the examples resolves tonew(),from_path()(which callsnew), orgenerate/generate_nonblocking(each of which callsnewtwice). 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
Configitself haspubfields and derivesDefault, so its validation is convention-enforced ratherthan type-enforced: nothing in the type system stops a future caller building one directly and skipping
ConfigBuilder::into_config. No such bypass exists today — everyConfig {literal was enumerated andthe 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_000andmax_command_buffer_size = 1_000_000succeeded before, returning aConfigwith 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:
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_sizespecifically to work around this defect, with a note saying the clamp should be revisited once this
lands. It becomes removable:
Channel::newnow clamps internally, so an inverted pair from thegenerator 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 iscommand_buffer_sizewhen the codechecks
max_buffer_size. Confirmed pre-existing and unrelated to this fix; filed as #1421 ratherthan left silent.
Validation, both feature shapes
Closes #1416.