Skip to content

Backport #115702 to 26.3: Fix integer overflow in String deserialization - #118199

Merged
alexey-milovidov merged 2 commits into
26.3from
backport/26.3/115702
Sep 5, 2026
Merged

alexey-milovidov merged 2 commits into
26.3from
backport/26.3/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 #118146

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.3.32.8

@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 [6d80565]

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.

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

🕵 Thanks, ported in 6d80565: deserializeBinaryBulkWithSizeStream now accumulates the sizes of the rows skipped by rows_offset in 128 bits and rejects a sum above MAX_TOTAL_STRING_SIZE with INCORRECT_DATA, the same hunk as #118201 and #118200. The gtest helper takes rows_offset and the new WithSizeStreamHugeSkippedSizeIsRejected covers the skipped-prefix path.

@alexey-milovidov
alexey-milovidov merged commit ffd3420 into 26.3 Sep 5, 2026
34 checks passed
@alexey-milovidov
alexey-milovidov deleted the backport/26.3/115702 branch September 5, 2026 16:18
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.

5 participants