Repository navigation
Cherry pick #117015 to 26.7: Bound the collections read from the Native protocol - #125269
Merged
robot-ch-test-poll merged 19 commits intoOct 12, 2026
Merged
Conversation
Several fields of the protocol are allocated at a size the peer declares before the data behind them arrives, and the collections among them had no bound that the data can plausibly have. In interserver mode `ClientInfo`, the settings and the externally granted roles of a query are deserialized before its secret hash is checked. - The settings and the query parameters of a query are read in a loop that ends on an empty name, with no bound on the number of pairs. - The strings of `ClientInfo` are short metadata - a user name, a host name, a quota key, a user agent, a URL - but were allowed a gigabyte each, and the number of current roles was allowed a billion entries, which is resized before the names are read. The `Hello` packet already bounds its fields. - The same for the externally granted roles. - `TablesStatusRequest` and `TablesStatusResponse` allowed a billion tables. - The obsolete `PartUUIDs` packet let a server make a client read sixteen gigabytes off the socket. `readVectorBinary` now takes the bound as an argument, so a caller that reads from an untrusted peer can pass what the data can plausibly hold.
`MAX_EXTRA_ROLES` is used in the interserver branch, which is compiled out when ClickHouse is built without SSL, so `-Wunused-const-variable` fails the build.
…rotocol-collection-limits
A bound on the number of elements is not enough: a `String` element is resized to its declared size before its value arrives in the same way the collection is, so a peer can declare a single role name or table identifier of a gigabyte and force the allocation on the same pre-authentication path. - `readVectorBinary` now takes a bound for the element as well, and `ClientInfo::read` and the externally granted roles of `TCPHandler` pass the identifier bound to it. - `TablesStatusRequest::read` and `TablesStatusResponse::read` bound the database and the table name. - The receiver-side limits are documented in the `NativeProtocol` specification. - The test covers the table-status paths, and is renumbered to avoid colliding with the tests merged into master.
…rotocol-collection-limits
… protocol The count bound on a settings or parameters sequence does not cover a single pair: a peer could declare a gigabyte-long setting or parameter name and never send it, forcing the allocation before the interserver hash is checked. A name is an identifier, so `BaseSettingsHelpers::readName` bounds it by the same 64 KiB as the strings of the `Hello` packet. The values keep the generic 1 GiB bound: a parameter is query-sized data, and the query text itself has to be read at that bound before the `auth_hash` covering it can be checked, so a tighter bound on values would break large parameters without lowering what a peer can make the server allocate. The test now speaks protocol revision 54459 so it can send a `Parameter` entry, and covers both names. The spec lists the new limit. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…rotocol-collection-limits Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…gtest Master switched `BaseSettingsHelpers::readString` to `readStringBinaryGrowing` and added `Settings.ADeclaredLengthOnTheSettingsWireIsNotAnAllocation`, which expects a 64 MiB declared name to run out of buffer. With the name bound of this PR the name is refused up front with `TOO_LARGE_STRING_SIZE` instead, so the case now expects that code. `readName` also reads growing, like `readString`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…them at 64 KiB `ClientInfo::read` also decodes the embedded `ClientInfo` of async `Distributed` queue files, and `ClientInfo` is forwarded to shards from the other interfaces, where e.g. an HTTP `query_id` or quota key can exceed 64 KiB. A 64 KiB cap made the server unable to drain queue files it wrote itself. Read the strings with `readStringBinaryGrowing` under the generic bound instead: a declared size still does not become an allocation on its own, and long legitimate values keep working. Add a test with a 100 KiB HTTP `query_id` through an async `Distributed` insert. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The unexpected-`Query` recovery path did not skip the externally granted roles that every client at `DBMS_MIN_PROTOCOL_VERSION_WITH_INTERSERVER_EXTERNALLY_GRANTED_ROLES` sends before the interserver hash, so the rest of the packet was parsed at wrong offsets. Also read the query id under the same bound as `processQuery` and the parameters with `readQueryParameters` instead of `Settings::read`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The count came from the peer and was only checked against `DEFAULT_MAX_STRING_SIZE`, so a client at revision 54480 or newer could make the server resize the vector to about 4 GiB before any bucket id arrived. A list of two-level aggregation bucket ids cannot name more than the 256 buckets. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…rotocol-collection-limits
…ead` with gtests The stateless harness speaks a revision below the one that carries `current_roles`, so the bound on the role count and on a role name had no coverage. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-collection-limits Bound the collections read from the Native protocol
…e conflicts The conflicts come from prerequisites that are not on 26.7: the valueless setting helpers (`throwValuelessSettingIsNotBool`, `throwValuelessSettingHasValue`, `formatValueForErrorMessage`), the `http_handler_name` / `http_request_url` fields of `ClientInfo` and the `setClientVersionFromConnectionIfUnknown` tests. Kept the 26.7 code and applied only the changes of #117015 on top of it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Original pull-request #117015
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job