Skip to content

Cherry pick #115708 to 25.8: Bound the size of the PostgreSQL startup message - #116000

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

robot-clickhouse merged 5 commits into
backport/25.8/115708from
cherrypick/25.8/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
…ypick/25.8/115708

# Conflicts:
#	src/Server/PostgreSQLHandler.cpp
@robot-clickhouse
robot-clickhouse merged commit f51fcc1 into backport/25.8/115708 Aug 26, 2026
@robot-clickhouse
robot-clickhouse deleted the cherrypick/25.8/115708 branch August 26, 2026 14:09
alexey-milovidov added a commit that referenced this pull request Aug 28, 2026
`reapplied_by` walked one level out from the direct remover, so it found the
revert that first put a change back and stopped there. With
`#109946` ← `#114911` ← `#114912` ← `#115500` ← `#116000` — out, back, out,
back, all inside one cycle — it reported only `#114912`, which the recorded
bullet already carried from the first restoration. The re-apply check was
therefore satisfied by the stale line and `#116000` was lost for good: a
revert of a revert has no bullet of its own, so the link on the entry is its
only trace in the release.

`revert_chain` now walks the whole chain above the entry, and the uncancelled
reverts of that chain are the ones that ship, so they are the ones that belong
on the bullet. `removed_by` is the complement — the cancelled ones — which also
makes the prompt name both removals of a repeated cycle instead of the first.
The three-pull-request case is unchanged: one remover, one re-applier.

The prompt asks for the links of every re-applier, noting that some may
already be on the recorded line from an earlier restoration.

`test_a_longer_chain_records_every_reapply` walks the five-pull-request
timeline and asserts `removed_by == ['114911', '115500']`,
`reapplied_by == ['114912', '116000']`, that replaying the recorded line is
rejected for missing `#116000`, and that appending it passes. It fails with
the one-level walk.
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