Skip to content

Backport #115702 to 26.6: Fix integer overflow in String deserialization - #118200

Merged
clickhouse-gh[bot] merged 4 commits into
26.6from
backport/26.6/115702
Sep 5, 2026
Merged

clickhouse-gh[bot] merged 4 commits into
26.6from
backport/26.6/115702

Conversation

@robot-clickhouse-ci-2

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #115702
Cherry-pick pull-request #118147

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.6.5.55

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Sep 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [9bbe427]

Summary: ✅

@zlareb1

zlareb1 commented Sep 5, 2026

Copy link
Copy Markdown
Member

TL;DR: this backport is missing one hunk that the 26.7 twin (#118201) has — the 128-bit guard on the bytes_to_skip prefix sum in deserializeBinaryBulkWithSizeStream.

The target branch carries the same untrusted-sizes overflow the PR fixes elsewhere, in the skipped-prefix path (src/DataTypes/Serializations/SerializationString.cpp, the for (size_t i = prev_size; i != prev_size + rows_offset; ++i) bytes_to_skip += sizes_data[i]; loop followed by stream->ignore(bytes_to_skip)). With rows_offset > 0 and corrupted/crafted sizes confined to the skipped prefix, the size_t sum wraps, ignore skips the wrong byte count, and the subsequent (now guarded) read consumes bytes from the wrong position — silently wrong string data instead of the intended INCORRECT_DATA rejection.

#118201 adds exactly this guard (unsigned __int128 bytes_to_skip_total + the MAX_TOTAL_STRING_SIZE check) as a branch-only adaptation; suggest porting the same hunk here before merge.

…ix the test signature

The 26.6 branch still has the `rows_offset` parameter of
`deserializeBinaryBulkWithMultipleStreams` (removed on master), so the
backported `gtest_string_serialization.cpp` did not compile (five arguments
where six are expected). Port the same branch-only adaptation as the 26.7
twin (#118201):

- `deserializeBinaryBulkWithSizeStream`: accumulate the sizes of the rows
  skipped by `rows_offset` in 128 bits and reject a sum above
  `MAX_TOTAL_STRING_SIZE` with `INCORRECT_DATA`, as the skipped prefix comes
  from the same untrusted sizes stream and an unchecked `size_t` sum could wrap
  and make `ignore` skip a wrong number of bytes.
- `expectSizesStreamRejected` takes `rows_offset`, holds the result as a
  `ColumnPtr` (the branch signature takes `ColumnPtr &`), and a new test
  `WithSizeStreamHugeSkippedSizeIsRejected` covers the skipped-prefix path.

CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=118200&sha=5bb0496be03bc66420b1316da678c4c25350ec6d&name_0=BackportPR&name_1=Build%20%28amd_debug%29
PR: #118200
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks, ported in 08dc0ad: the bytes_to_skip prefix sum in deserializeBinaryBulkWithSizeStream now accumulates in 128 bits and rejects a total above MAX_TOTAL_STRING_SIZE with INCORRECT_DATA, same as the 26.7 twin, and the new WithSizeStreamHugeSkippedSizeIsRejected gtest covers it.

The same commit also fixes the reason all three builds were red here: on this branch deserializeBinaryBulkWithMultipleStreams still takes rows_offset and a ColumnPtr &, so the test as backported from master did not compile. Note that #118201 carries the same ColumnPtr & mismatch (it passes *result) and its builds are red for the same reason; it needs the analogous one-line fix in expectSizesStreamRejected.

alexey-milovidov added a commit that referenced this pull request Sep 5, 2026
Port the same branch-only adaptation as the 26.6 and 26.7 twins
(#118200,
#118201), as requested in the
review of this PR:

- `deserializeBinaryBulkWithSizeStream`: accumulate the sizes of the rows
  skipped by `rows_offset` in 128 bits and reject a sum above
  `MAX_TOTAL_STRING_SIZE` with `INCORRECT_DATA`. The skipped prefix comes from
  the same untrusted sizes stream, so an unchecked `size_t` sum could wrap and
  make `ignore` skip a wrong number of bytes, yielding silently wrong string
  data instead of a rejection.
- `expectSizesStreamRejected` takes `rows_offset`, and the new gtest
  `WithSizeStreamHugeSkippedSizeIsRejected` covers the skipped-prefix path.

PR: #118199

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=118200&sha=08dc0ad5bb7e1ac4087de91e9daa77f7342443d9&name_0=BackportPR&name_1=Stress%20test%20%28amd_tsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The only red here is Stress test (amd_tsan), and it is unrelated to this backport: the server aborts in DB::RefreshTask::doScheduling (src/Storages/MaterializedView/RefreshTask.cpp:936) with Logical error: 'Unexpected exception in refresh scheduling', which then makes the restart step report Cannot start clickhouse-server. Nothing in that path touches SerializationString.

This is the same signature as #106737 (STID 2508-3e7b), which was closed by #108441 and #108890, but CIDB shows it still reproducing on master roughly every few days through 2026-08 and 2026-09 (e.g. 2026-08-13, 08-16, 08-18, 08-19, 08-23, 08-24, 08-29, 08-30, 08-31, 09-03), so the closed issue likely needs to be reopened or a new one filed for the remaining path.

The base branch 26.6 has been merged and pushed here (9bbe427c40eb) so CI re-runs on a current base.

@groeneai

groeneai commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

No fix is in progress, so there is nothing to link. The fix is already on master: this red is a release branch gap, not a residual master path.

Master is clean, and the 2026-08/09 dates are 26.6 rows. pull_request_number = 0 covers release branches as well as master, so the true master predicate needs both columns. With head_ref = 'master' AND pull_request_number = 0, the signature has 35 hits in 180 days, all between 2026-06-16 and 2026-06-29 17:59:37, and #108441 merged that same day at 17:39:47Z. Nothing since, over 36,772 master Stress jobs in 90 days. Every date you listed is head_ref = '26.6', pull_request_number = 0, i.e. ReleaseBranchCI.

Branch cut date against merge date, confirmed by content markers in RefreshTask.cpp, with one 90 day CIDB window:

Branch cut #108441 #108890 Stress jobs signature hits
master yes yes 36772 35, none after 2026-06-29
26.8 2026-08-24 yes yes 1017 0
26.7 2026-07-22 yes no 2274 0
26.6 2026-06-23 no no 3603 18, 9 flavours, latest 2026-09-03
26.3 2026-03-19 no no 1954 0, but the carrier test is absent there

No cherry-pick or backport PR exists for either fix (control: the same search for #113188 returns 5).

Mechanism on this run. The Stress harness randomizes the Keeper feature flags, and here it wrote <multi_read>0</multi_read> before a restart (job log 08:56:07, Replacing multi_read with 0). On 26.6 the constructor checks MULTI_READ and CREATE_IF_NOT_EXISTS only under if (!attach && !is_restore_from_backup) (RefreshTask.cpp:156-162), so the re-attaching view proceeds, readZnodesIfNeeded throws NOT_IMPLEMENTED on the scheduling thread (:1391), and the catch-all aborts at :936, the frame in your stack. #108441 is exactly that fix: on attach it enters a permanent "coordination unavailable" state instead (master :210-218).

26.7 is the natural experiment: it carries #108441 but not #108890, it runs the carrier test (215 commits in the window), and it has zero hits. So #108441 alone removes the observed signature, and #108890 closes only the residual re-check race that 26.7 has never exhibited.

Off CI the abort is DEBUG_OR_SANITIZER_BUILD gated, so a shipped 26.6 build does not abort. Instead the catch-all sets stop_requested and re-schedules unconditionally, re-throwing the same NOT_IMPLEMENTED immediately: on the official 26.6.3.57 binary against a Keeper with multi_read=0 I measured 1,753,852 exceptions in about 13 minutes (roughly 27k per second, 2.7 GB of clickhouse-server.err.log), with the view pinned in status = Scheduling. 26.7.4.54 in the same setup produces zero and the view goes to Disabled.

What I need is the label, not a hand written release branch PR, per @ pufit's rule that you reaffirmed on #111910 on 2026-07-27. Could you apply v26.3-must-backport to #108441? That is the same ask I left on that PR on 2026-08-18 (still the newest comment there), with the per branch merge test. It expands to 26.3, 26.6, 26.7 and 26.8, and 26.7 and 26.8 are skipped automatically since they already contain the commit. #108890 can follow once #108441's cherry-pick has merged, since it refactors the state #108441 introduces, and by the 26.7 evidence it is not needed to clear this red.

On #106737: the master data supports its closure, and the remaining exposure is release branch only, so I would not reopen it on this evidence. If you would rather track the release branch gap in a new issue than through the label, say so and I will open one.

@clickhouse-gh
clickhouse-gh Bot merged commit d6eab50 into 26.6 Sep 5, 2026
76 of 78 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.6/115702 branch September 5, 2026 16:56
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thank you, the analysis is right: the signature is confined to 26.6 (and the code is equally present on 26.3), 26.7 carries #108441 and is clean, and I withdraw the suggestion to reopen #106737.

I have applied the v26.3-must-backport label to #108441, so the robot will produce the 26.3 and 26.6 backports; 26.7 and 26.8 already contain the commit and will be skipped. #108890 can follow once that cherry-pick has merged, as you suggest. No new issue is needed since the label tracks the gap.

This PR itself is merged, so nothing else remains here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants