Skip to content

Bound column count in inserted RowBinary header - #120282

Merged
rschu1ze merged 1 commit into
masterfrom
fix-69219-rowbinary-header-column-count
Sep 24, 2026
Merged

rschu1ze merged 1 commit into
masterfrom
fix-69219-rowbinary-header-column-count

Conversation

@george-larionov

@george-larionov george-larionov commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

The column count in the RowBinaryWithNames[AndTypes] header was read with readVarUInt and used unbounded as a loop bound in readHeaderRow and as a reserve argument in readTypes. readVarUInt limits the number of bytes consumed, not the decoded value, so an INSERT ... FORMAT RowBinaryWithNamesAndTypes could turn a small upload into a large server-side allocation.

Reject a header column count above DEFAULT_NATIVE_BINARY_MAX_NUM_COLUMNS with TOO_LARGE_ARRAY_SIZE at all three read sites (readNames, skipNames, skipTypes), matching the existing check in NativeReader and MsgPackRowInputFormat.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Bound the header column count in RowBinary formats to avoid excessive memory allocation from a crafted header.


Workflow [PR]
Sync PR [sync-upstream/pr/120282]

Version info

  • Merged into: 26.10.1.635-master (included in 26.10 and later)
  • Backported to: 26.9.2.33, 26.8.11.41, 26.7.14.40, 26.3.33.144

BinaryFormatReader read the header column count with readVarUInt and used
it unbounded as a loop bound in readHeaderRow and as a reserve() argument
in readTypes. readVarUInt limits the bytes consumed, not the decoded value,
so an INSERT ... FORMAT RowBinaryWithNamesAndTypes could amplify a small
upload into a large server-side allocation.

Reject a header column count above DEFAULT_NATIVE_BINARY_MAX_NUM_COLUMNS
with TOO_LARGE_ARRAY_SIZE at all three read sites (readNames, skipNames,
skipTypes), matching the existing check in NativeReader and
MsgPackRowInputFormat.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7c22790]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR IGNORED

AI Review

Summary

This PR bounds the RowBinaryWithNames* header column count before that value is reused as a loop bound and reserve hint, closing the small-input-to-large-allocation path described in the PR. The guard is applied on the ingestion path and on the shared schema-reader path, and I did not find new correctness or compatibility issues in the current diff.

Missing context / blind spots
  • ⚠️ I did not inspect CI artifacts or run the new stateless test locally; a targeted run of 04603_rowbinary_header_too_many_columns.sh would close that gap.
Final Verdict

✅ No actionable review findings in the current version of this PR.

LLVM Coverage Report

Measured on commit 7c22790.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 80.60% 80.60% +0.00%

Changed lines: Changed C/C++ lines covered: 5/13 (38.46%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 15, 2026
@george-larionov george-larionov changed the title Bound column count in RowBinary header Bound column count in inserted RowBinary header Sep 15, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Sep 15, 2026
@george-larionov george-larionov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 16, 2026
@rschu1ze

Copy link
Copy Markdown
Member

@Avogar Maybe you like to take a look at this PR?

@rschu1ze rschu1ze self-assigned this Sep 22, 2026
@rschu1ze
rschu1ze added this pull request to the merge queue Sep 24, 2026
Merged via the queue into master with commit 685b7a2 Sep 24, 2026
174 of 176 checks passed
@rschu1ze
rschu1ze deleted the fix-69219-rowbinary-header-column-count branch September 24, 2026 20:23
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 24, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 24, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 24, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 24, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 24, 2026
Backport #120282 to 26.8: Bound column count in inserted RowBinary header
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 24, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 24, 2026
Backport #120282 to 26.9: Bound column count in inserted RowBinary header
clickhouse-gh Bot added a commit that referenced this pull request Sep 24, 2026
Backport #120282 to 26.7: Bound column count in inserted RowBinary header
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
PedroTadim added a commit that referenced this pull request Sep 25, 2026
Backport #120282 to 26.3: Bound column count in inserted RowBinary header
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants