Skip to content

Cherry pick #115708 to 26.5: Bound the size of the PostgreSQL startup message - #116002

Merged
robot-clickhouse merged 5 commits into
backport/26.5/115708from
cherrypick/26.5/115708
Aug 26, 2026
Merged

robot-clickhouse merged 5 commits into
backport/26.5/115708from
cherrypick/26.5/115708

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #115708

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-pick locally.
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.

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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

Bounding the declared size of the startup message is not enough on its own:
`StartupMessage::deserialize` reads parameter names and values with
`readNullTerminated`, which keeps appending to the string until the next `'\0'`
arrives, regardless of the declared size. A client could therefore declare a tiny
startup packet and then stream an arbitrarily long unterminated parameter,
consuming memory before authentication.

Wrap the connection in a `LimitReadBuffer` bounded by the declared payload size
in `MessageTransport::receiveWithPayloadSize`, so the parser cannot read past the
end of the message. The remaining-size check inside `StartupMessage::deserialize`
stays as a consistency check within that bounded payload.

Add a socket-level test that declares a small startup message and then streams
bytes without a terminator.

Address review: #115708
…sage-size

Bound the size of the PostgreSQL startup message
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Aug 23, 2026
Resolved a conflict in `src/Server/PostgreSQLHandler.cpp`: 26.5 has no
`classifyNoOpDriverCommand` anonymous-namespace block and no
`UNEXPECTED_PACKET_FROM_CLIENT` error code (both come from unrelated master
changes), so only the `UNKNOWN_PACKET_FROM_CLIENT` declaration needed by
#115708 was kept.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants