Skip to content

Backport #110590 to 26.6: Validate the JSON/Object shared-data bucket count read from a stream - #117743

Merged
clickhouse-gh[bot] merged 2 commits into
26.6from
backport/26.6/110590
Sep 2, 2026
Merged

clickhouse-gh[bot] merged 2 commits into
26.6from
backport/26.6/110590

Conversation

@Avogar

@Avogar Avogar commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Manual backport to 26.6 of the shared-data bucket count validation added in #110590 (commit 73641c7f1d1), plus a stateless test for it.

Not a cherry-pick: that commit is an incremental rename of an earlier throwIfTooManyBuckets introduced by two predecessor commits which also change the path-count handling and SerializationDynamic, and neither of those is backported here.

Related: #117739

Version info

  • Merged into: 26.6.5.32

Manual backport of the guard added in #110590
(commit `73641c7f1d1`). It cannot be cherry-picked, because that commit is an incremental
rename of an earlier `throwIfTooManyBuckets` introduced by two predecessor commits which
also change the path-count handling and `SerializationDynamic`, and neither of those is
backported here.

An `Object` V3 structure prefix carries the shared-data bucket count as a bare varint, and
that count sizes the per-bucket reader state and `Columns` directly. A malformed `Native`
block declaring `0` buckets therefore made `collectSharedDataFromBuckets` index an empty
vector, and a count near `SIZE_MAX` escaped as a non-`DB::Exception` allocation failure.

Reject anything outside `1 .. MAX_OBJECT_SHARED_DATA_BUCKETS` as `INCORRECT_DATA`, and point
the writer-side setting caps at the same constant so the reader guard and the writer bound
cannot drift.

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

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [0a70c98]

Summary: ✅

The range check and the error message already say what the guard does, and the reason the
range is `1 .. 256` is documented on `MAX_OBJECT_SHARED_DATA_BUCKETS` itself.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh
clickhouse-gh Bot merged commit 6a29aa9 into 26.6 Sep 2, 2026
38 of 39 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.6/110590 branch September 2, 2026 20:29
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
…26.3 backport ClickHouse#117748)

PROTO: a Dynamic or JSON/Object structure read from a stream (Native input, the format() table function, a corrupted
part) with a type or path count near SIZE_MAX -> an uncaught std::length_error instead of a DB::Exception; with a
large but representable count, a multi-GB up-front reserve before any type or path is read (OOM/DoS). Also the
`num_dynamic_types + 1` wrap-around for SIZE_MAX.
Effect in the production build a394e92: the upstream tests 04307_dynamic_flattened_too_many_types and
04350_json_native_too_many_paths fail on it and pass on official 26.8.8.8, run on isolated servers
(evidence/fix_ci_20260925/upstream_repro/server_triage_PROD263_vs_UP2688.tsv).
ClickHouse#110590 is an upstream port of Cloud-only tests that carries several fixes; its 26.3 (ClickHouse#117748) and 26.6 (ClickHouse#117743)
backports take only the shared-data bucket guard. This commit adds its other guards unchanged: SerializationDynamic.cpp
(flattened type count, V2 dynamic type count), SerializationObject.cpp (flattened and dynamic path counts; the helper
joins the anonymous namespace that ClickHouse#117748 created; the fork keeps its own declarations there) and SerializationObjectSharedData.cpp (granule path and substream
counts), with the upstream tests 04307 and 04350 and their four Native fixtures (blob ids equal to the upstream diff).
The gtest and documentation changes of ClickHouse#110590 are not included.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant