Skip to content

Add stateless tests ported from the Cloud-only test suite - #110590

Merged
alexey-milovidov merged 15 commits into
masterfrom
move-private-only-tests-to-public
Jul 19, 2026
Merged

alexey-milovidov merged 15 commits into
masterfrom
move-private-only-tests-to-public

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

Adds several stateless tests ported from the ClickHouse Cloud-only test suite, and hardens Native-format deserialization of Dynamic and JSON/Object columns against corrupted type/path count headers.

One of the ported tests (04307_dynamic_flattened_too_many_types) surfaced a real bug: reading a Native-format stream with a corrupted num_types / num_dynamic_types count close to SIZE_MAX made std::vector::reserve / resize throw an uncaught std::length_error instead of a normal DB::Exception. SerializationDynamic now validates the count against ColumnDynamic::MAX_DYNAMIC_TYPES_LIMIT before doing any arithmetic on it (so a corrupted count of exactly SIZE_MAX can no longer wrap the + 1 around to 0 and slip past the check) and throws INCORRECT_DATA with the offending count. The same class of unchecked count in SerializationObject::deserializeObjectStructureStatePrefix (the flattened_paths / dynamic_paths sizes) is now translated into a catchable INCORRECT_DATA error as well (04350_json_native_too_many_paths), and the official Native format specification (docs/en/interfaces/specs/NativeFormat.md) is updated with the normative malformed-count contract.

These tests were surveyed out of ~260 stateless and ~118 integration tests that exist only in the private/Cloud fork. Most of the remainder genuinely depend on Cloud-only features (SharedMergeTree, Shared Catalog, server-side JWT, masking policies, the distributed cache, etc.) and were left out. Two packed-part-storage tests (02790_packed_parts_refcount, 04401_packed_skip_indices_concurrent_read_long) were dropped from this PR: packed part storage isn't wired up on public master yet, so they don't currently exercise what they claim to, and both are already being ported together with the feature itself in #108118. A further ~12 tests looked plausible from reading the code but, once actually run against a local build, turned out to depend on things not yet in public master (a system.parts.part_storage_type column, the timeSeriesIrateToGrid / timeSeriesIdeltaToGrid aggregate functions, a cloud_mode validation check on remote_filesystem_read_method, and a few reference-value mismatches that need further investigation) — those are being tracked separately rather than included here to avoid landing red or under-verified tests.

Each test in this PR was run against a freshly built binary (server + local minio where needed, --no-random-settings --no-random-merge-tree-settings) and confirmed passing before being added.

Related: #108118

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):

Fixed reading a corrupted Native-format stream whose Dynamic type count or JSON/Object path count is close to SIZE_MAX: such malformed input is now rejected with a clear INCORRECT_DATA error instead of an uncaught std::length_error.

Documentation entry for a feature (a user-readable short description of the changes that goes into user-facing documentation.md):

N/A

Version info

  • Backported to: 26.6.5.32, 26.3.30.7

alexey-milovidov and others added 2 commits July 15, 2026 16:22
These 8 tests exercise generic MergeTree/packed-storage/Dynamic-type
behavior that does not depend on SharedMergeTree, Shared Catalog, or
any other Cloud-only feature, but previously only existed in the
Cloud fork's test suite. Verified against a local build (server +
minio) with --no-random-settings before porting.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…tive format

Reading a Native-format stream with a corrupted `num_types`/`num_dynamic_types`
count close to SIZE_MAX made `std::vector::reserve` throw an uncaught
std::length_error instead of a catchable DB::Exception, producing an
unhelpful crash-like failure instead of an informative error. Convert
that specific exception into `INCORRECT_DATA` with the reported count.

Test ported from the Cloud-only test suite (verified failing without
this fix, passing with it, against a local build).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1b47fac]

Summary: ✅


AI Review

Summary

This PR ports several stateless tests from the Cloud-only suite and hardens Dynamic / JSON / Object deserialization against malformed count prefixes in Native and MergeTree paths. Most of the previously exposed malformed-count holes are fixed, but one non-flat Object count is still only treated as an allocation hint instead of being validated against the format's own writer-side limit, so corrupted input can still materialize an impossible number of dynamic subcolumns rather than being rejected as INCORRECT_DATA.

Findings

⚠️ Majors

  • [src/DataTypes/Serializations/SerializationObject.cpp:767] Non-flat Object still accepts payload-backed dynamic_paths_size values above DataTypeObject::MAX_DYNAMIC_PATHS_LIMIT, even though valid V1 / V2 / V3 data cannot have more explicit dynamic paths than that because overflow paths live in shared data. deserializeBinaryBulkWithMultipleStreams later calls setMaxDynamicPaths / setDynamicPaths with this count, so malformed input can still force creation of tens of thousands of Dynamic subcolumns instead of being rejected as corruption.
    Suggested fix: reject dynamic_paths_size > DataTypeObject::MAX_DYNAMIC_PATHS_LIMIT (or an equivalent shared non-flat-format constant) before reading path names, and add a focused regression test for MAX_DYNAMIC_PATHS_LIMIT + 1.
Final Verdict
  • Status: ⚠️ Request changes
  • Reject non-flat Object streams whose dynamic-path count exceeds the legal writer-side maximum, and cover that invariant with a regression test.

@clickhouse-gh clickhouse-gh Bot added the pr-build Pull request with build/testing/packaging improvement label Jul 15, 2026
…thmetic

`reserveOrThrowTooManyTypes` relied on `std::vector::reserve` throwing
`std::length_error` to catch a corrupted `num_dynamic_types`. But the call
site computed `num_dynamic_types + 1` before reserving, so a corrupted
count equal to `SIZE_MAX` wraps around to `0` and bypasses the check
entirely. Validate `num_dynamic_types` against
`ColumnDynamic::MAX_DYNAMIC_TYPES_LIMIT` before the `+ 1`, and update the
`04307_dynamic_flattened_too_many_types` V2 fixture to encode `SIZE_MAX`
so it exercises exactly this case.

Also add the `no-parallel` tag to `03057_private_attach_disk_web`, matching
`03355_mergetree_table_disk` and `03823_table_disk_cache_key_collision`:
without it, CI runs multiple copies of the test concurrently, which collide
on the test's hardcoded table UUID (`TABLE_ALREADY_EXISTS` "UUID collision").

Drop `02790_packed_parts_refcount` and `04401_packed_skip_indices_concurrent_read_long`:
packed part storage (`min_bytes_for_full_part_storage`) isn't wired up on
master yet, so these currently don't exercise what they claim to, and both
paths are already being ported together with the feature itself in #108118.
The previous commit's message described these changes, but a pathspec
error in a batched `git add` silently dropped everything except the two
test-file deletions from the staged diff.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

CI notes on unrelated failures from the last run:

Also addressed in the latest push:

  • Added no-parallel to 03057_private_attach_disk_web (per review): without it CI runs multiple copies of the test concurrently, which collide on the test's hardcoded table UUID.
  • Fixed the Dynamic-type-count validation to check ColumnDynamic::MAX_DYNAMIC_TYPES_LIMIT before the overflow-prone + 1 (per review), and updated the 04307_dynamic_flattened_too_many_types V2 fixture to encode the exact SIZE_MAX case this guards against.
  • Dropped 02790_packed_parts_refcount and 04401_packed_skip_indices_concurrent_read_long (per review): packed part storage isn't wired up on master yet, so these don't currently exercise what they claim to, and both are already being ported together with the feature itself in Open-source packed part storage #108118.
  • Merged master to pick up ~170 commits of drift.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Follow-up on the ZeroCopyLock/Keeper-component failure noted above: opened #110664 to fix it directly instead of just flagging it.

@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed: #110664 covers this call site. The 'Current component is empty' abort came from 'zero_copy_lock''s dtor issuing the ephemeral-node release when a task is destroyed while still holding the lock (cancellation before the explicit unlock), running from generic background-task cleanup with no component scope. #110664 guards it in explicit destructors for both 'MutateFromLogEntryTask' (reported) and 'MergeFromLogEntryTask' (identical latent sibling), matching the 'DDLWorker::shutdown' / 'EphemeralNodeHolder' precedent and the #109297 / #98663 / #107266 class. Deferring to your PR, no separate one from us.

@groeneai

Copy link
Copy Markdown
Collaborator

Investigated and fixed in a separate PR: #110670.

Root cause: ZooKeeperLock::~ZooKeeperLock() -> unlock() issues Keeper exists/remove to release the ephemeral node. When a still-locked ZeroCopyLock is destroyed by the background executor (here via MutateFromLogEntryTask's member) it runs outside any component scope, so pushRequest throws "Current component is empty". Fix sets the component in the destructor, covering every ZooKeeperLock release path.

Reproduced deterministically (s3 zero-copy RMT + enforce_keeper_component_tracking, pause the mutation after the lock is taken, then drop the table) and confirmed it aborts without the change and passes with it; stateless regression test included.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jul 16, 2026
A replicated zero-copy merge/mutate task owns the zero-copy exclusive lock
via its std::optional<ZeroCopyLock> member. When the task is torn down on a
MergeTreeBackgroundExecutor thread while the lock is still held, ~ZooKeeperLock
issues Keeper requests (exists/remove) to release the ephemeral node. That
teardown runs outside any component scope, so with enforce_keeper_component_tracking
enabled the server aborts with "Current component is empty, please set it for
your scope using Coordination::setCurrentComponent".

The Keeper component is set at the highest level that owns the section doing
those ZooKeeper requests: the MutateFromLogEntryTask / MergeFromLogEntryTask
destructors. Each explicitly releases zero_copy_lock inside the guarded scope,
because the member would otherwise be destroyed after the destructor body,
outside the guard.

Regression test 04546 pauses a mutation task on a new failpoint fired right
after tryCreateZeroCopyExclusiveLock() succeeds, so the task provably holds the
lock, then drops the table so the task is destroyed with the lock still held.

Related: ClickHouse#110590
Address review (AI-review Major on #110590): the previous commits only closed
the malformed-count bug for `Dynamic`. `SerializationObject::deserializeObjectStructureStatePrefix`
still read the `flattened_paths` / `dynamic_paths` counts straight from an
untrusted `Native` stream and passed them to `resize`, so a corrupted `JSON` /
`Object` block near `SIZE_MAX` could still throw an uncaught `std::length_error`
instead of a normal `DB::Exception`.

Translate the `std::length_error` from those `resize` calls (and the nearby
`shared_data_paths_statistics.reserve`) into a catchable `INCORRECT_DATA` error,
mirroring the `Dynamic` fix.

Add `04350_json_native_too_many_paths`, a companion to
`04307_dynamic_flattened_too_many_types`, exercising both the `FLATTENED` and
the non-flat path-count sites with hand-crafted corrupted `Native` fixtures.

Update the `Native` format specification with the normative "malformed counts"
contract for both `Dynamic` and `JSON`/`Object`.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Addressed the AI-review Request changes verdict from the previous run:

  • Major (sibling JSON/Object path): SerializationObject::deserializeObjectStructureStatePrefix read the flattened_paths / dynamic_paths counts straight from an untrusted Native stream into resize, so a corrupted JSON/Object block near SIZE_MAX could still throw an uncaught std::length_error. Those resize calls (and the nearby shared_data_paths_statistics.reserve) now translate std::length_error into a catchable INCORRECT_DATA ("JSON/Object column has too many paths: N"), mirroring the Dynamic fix.
  • Test: added 04350_json_native_too_many_paths, a companion to 04307_dynamic_flattened_too_many_types, with hand-crafted corrupted Native fixtures for both the FLATTENED (flattened_paths) and non-flat (dynamic_paths) count sites; both now fail with INCORRECT_DATA.
  • Spec: docs/en/interfaces/specs/NativeFormat.md gains a normative "malformed counts" note for both Dynamic and JSON/Object (a decoder must treat these wire counts as untrusted and reject out-of-range values as corruption).
  • Changelog: reclassified to Bug Fix with a short changelog entry, since the PR now carries a user-visible behavior change (uncaught std::length_error → clean INCORRECT_DATA) alongside the ported tests.

Also merged master (726 commits of drift). Verified against a freshly built binary: the two new fixtures reject with INCORRECT_DATA, 04307 still passes, and valid JSON round-trips (V1 / FLATTENED / subcolumn reads) are unchanged.

@mintlify

mintlify Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Jul 16, 2026, 5:44 PM

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-build Pull request with build/testing/packaging improvement labels Jul 16, 2026
alexey-milovidov and others added 2 commits July 17, 2026 03:13
…NAMIC_TYPES_LIMIT

Addresses the AI-review Major on `docs/en/interfaces/specs/NativeFormat.md`:
the "Malformed counts" note told a decoder to validate the flattened `Dynamic`
`num_types` against `ColumnDynamic::MAX_DYNAMIC_TYPES_LIMIT`. That is wrong for
the flattened layout: `flattenDynamicColumn` writes *every* distinct runtime
type, including those that had overflowed into the shared variant, so a valid
flattened block can legitimately list far more than the limit. A decoder built
from that sentence would reject valid flattened streams.

Clarify that the `MAX_DYNAMIC_TYPES_LIMIT` bound applies only to the non-flat
`V1`/`V2`/`V3` `num_dynamic_types` (which counts regular-variant slots), matching
what ClickHouse actually validates in `SerializationDynamic`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…own exception

Addresses the AI-review Major on `SerializationObject.cpp`: the malformed-count
helpers translated only `std::length_error` into `INCORRECT_DATA`. That is
correct for `std::vector::resize`, but a hash table's `reserve` does not throw
`std::length_error` for a corrupted `SIZE_MAX`-family count. `reserveOrThrowTooManyPaths`
wraps `shared_data_paths_statistics.reserve` (an `UnorderedMapWithMemoryTracking`);
on libc++ with ClickHouse's `AllocatorWithMemoryTracking` that path throws
`std::bad_alloc`, on libstdc++ `std::bad_array_new_length`. The corrupted count
therefore escaped as a non-`DB::Exception`.

Replace the catch-based helpers with an up-front check that rejects a count the
container cannot possibly hold (`> max_size()`) as `INCORRECT_DATA`, and
additionally cap the `reserve` sizing hint so no representable count can overflow
the bucket arithmetic or over-allocate -- independent of the standard library and
allocator. A legitimate large count still grows the container on demand, and a
corrupted count trips a normal read error in the loop that follows.

Add gtest `ObjectSerialization.TooManySharedDataPathsStatistics`, which reaches
the statistics `reserve` site with `object_and_dynamic_read_statistics` enabled
(the MergeTree part read path, which the `Native` input format used by
`04350_json_native_too_many_paths` never reaches) and asserts a clean
`INCORRECT_DATA`.

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

Copy link
Copy Markdown
Member Author

Addressed the AI-review Request changes verdict (both Majors + the Tests note):

  • Major (SerializationObject.cpp): the malformed-count helper wrapped shared_data_paths_statistics.reserve (a hash map) with only catch (std::length_error), but a hash table's reserve doesn't throw std::length_error for a corrupted SIZE_MAX-family count — on our libc++ build with AllocatorWithMemoryTracking it throws plain std::bad_alloc (not even std::bad_array_new_length). Replaced the catch-based helpers with an up-front if (num_paths > container.max_size()) → INCORRECT_DATA check, and additionally capped the reserve sizing hint, so a corrupted count is rejected independent of the standard library and no representable count can overflow the bucket arithmetic. (4658154)
  • Tests: added gtest ObjectSerialization.TooManySharedDataPathsStatistics, which reaches the statistics reserve site with object_and_dynamic_read_statistics enabled (the MergeTree part read path — Native input, exercised by 04350_json_native_too_many_paths, never enables statistics) and asserts a clean INCORRECT_DATA. (4658154)
  • Major (NativeFormat.md): the "Malformed counts" note wrongly told a decoder to bound the flattened Dynamic num_types by ColumnDynamic::MAX_DYNAMIC_TYPES_LIMIT. The flattened list carries every distinct type (including those spilled into the shared variant), so it can exceed the limit; the note now scopes that bound to the non-flat num_dynamic_types, matching what SerializationDynamic actually validates. (7fa48bb)

Verified against a freshly built binary: the new gtest passes, 04307/04350 still produce their exact reference messages, and valid JSON round-trips (V1, FLATTENED, and a 50-key column mostly in shared data) are unaffected.

@clickhouse-gh

clickhouse-gh Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This PR hardens Native-format and on-disk deserialization of JSON/Object/Dynamic columns against malformed path/type/bucket counts (plus docs and tests); it does not touch the SELECT execution path that ClickBench Q4 and Q15 exercise. Both queries show ~20% faster wall time but flat CPU time (Q4 2658.5→2683.4 ms, Q15 2607.1→2610.4 ms), and both land inside master's current variance band, so the deterministic gate correctly suppressed them as run-to-run variance. No real regressions or improvements attributable to this change.

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: b59ce9b1-ad87-49d9-b59e-360159249b60
  • MIRAI run: 6c1bc397-67df-457b-a68e-8e9238708b25
  • PR check IDs:
    • clickbench_279752_1784429591
    • clickbench_279758_1784429591
    • clickbench_279768_1784429591
    • tpch_adapted_1_official_279775_1784429591
    • tpch_adapted_1_official_279787_1784429591
    • tpch_adapted_1_official_279800_1784429591

@alexey-milovidov

Copy link
Copy Markdown
Member Author

CH Inc sync triage (private sync PR ClickHouse/clickhouse-private#64632, commit fc708a14):

The sync PR merges cleanly (MERGEABLE) and builds; only 3 test jobs failed, all unrelated to this PR's changes (which are confined to Native deserialization of Dynamic/JSON/Object). This PR's own new tests 04307_dynamic_flattened_too_many_types and 04350_json_native_too_many_paths both passed in the private stateless run.

  • Stateless (amd_ubsan): 00965_send_logs_level_concurrent_queries — known flaky concurrency/log-ordering test (harness auto-classified it flaky); plus the Scraping system tables post-step matched flaky issue Scraping system tables #110816.
  • Integration (amd_tsan, 3/6): test_storage_kafka::test_kafka_formats_with_broken_message — accompanied by ZooKeeper connection-retry failures; timing-dependent, unrelated area.
  • Stress (amd_msan): Received signal 8 (SIGFPE) in EnabledQuota::getEndOfInterval ← QuotaCache::rebuildIntervals — the known quota zero-length-interval crash, tracked in UndefinedBehaviorSanitizer: undefined behavior (STID: 4141-5b13) #110343 (fix in progress in Disable zero-length interval quotas #110846); Access/Quota subsystem, untouched here.

None touch SerializationDynamic/SerializationObject/SerializationObjectSharedData. Re-triggered the failed private jobs so the sync check reflects a clean rerun.

@alexey-milovidov alexey-milovidov self-assigned this Jul 18, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 18, 2026
The test is a heavy `long` test (10M-row insert, `OPTIMIZE FINAL`, then 51
full-column scans). The flaky check runs each changed test many times with
high concurrency (18 workers), and under that load a single run of this test
exceeds the 600s per-test timeout.

It only surfaced in the merge queue: the test is tagged
`no-tsan, no-debug, no-asan, no-msan`, so it was skipped in every flaky check
of the pull-request run (all sanitizer/debug builds) and only actually ran in
the merge queue's `amd_binary` (release) flaky check, where it timed out.

`no-flaky-check` is the intended tag for heavy `long` tests that cannot be run
concurrently many times within the per-test timeout; the test still runs
normally in the regular stateless test runs.

Merge queue report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=gh-readonly-queue/master/pr-110590-b702eb6e293229f8acad13801147208fa5101a03&sha=1ad06830742db2a6e2c9b89e17e3a7d1915de5ad&name_0=MergeQueueCI&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29
https://github.com/ClickHouse/ClickHouse/actions/runs/29651650653/job/88100774571

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…the Native spec

The "Malformed counts" note in the FLATTENED `Object` section wrongly
attributed a `flattened-paths` count to the non-flat `V1`/`V2`/`V3`
encodings. Per `SerializationObject::deserializeObjectStructureStatePrefix`,
only the `FLATTENED` prefix reads a flattened-paths count; the non-flat
`V1`/`V2`/`V3` prefixes carry only the dynamic-paths count (plus a
`max_dynamic_paths` value that `V1` reads and discards, and the `V3`
shared-data metadata). A decoder written from the old sentence would look
for a nonexistent field in non-flat streams and reject valid data.

Split the sentence into the actual cases: `num_dynamic_paths` for the
FLATTENED layout documented here, and the dynamic-paths count for the
non-flat `V1`/`V2`/`V3` encodings.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
/// Read the sorted list of dynamic paths.
/// Read the sorted list of dynamic paths (same append-on-demand handling as flattened paths).
size_t dynamic_paths_size = 0;
readVarUInt(dynamic_paths_size, *structure_stream);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-flat Object never legitimately serializes this many explicit dynamic paths. Once a JSON column reaches its max_dynamic_paths, overflow paths move into shared data instead, and the type-level hard cap for dynamic paths is DataTypeObject::MAX_DYNAMIC_PATHS_LIMIT (10000).

With the current code, a payload-backed corrupted count like 50000 is still accepted: deserializeBinaryBulkWithMultipleStreams later does column_object.setMaxDynamicPaths(dynamic_paths_size) and setDynamicPaths(...), so we materialize 50k Dynamic subcolumns instead of rejecting the stream as malformed. The capped reserve fixes the truncated-input OOM, but it still leaves this impossible non-flat V1/V2/V3 count outside the writer-side contract. Please reject dynamic_paths_size > DataTypeObject::MAX_DYNAMIC_PATHS_LIMIT up front and add a focused regression test for MAX_DYNAMIC_PATHS_LIMIT + 1.

@clickhouse-gh

clickhouse-gh Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 78.20% 78.20% +0.00%

Changed lines: Changed C/C++ lines covered: 165/179 (92.18%) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 19, 2026
Merged via the queue into master with commit b40ebbc Jul 19, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the move-private-only-tests-to-public branch July 19, 2026 16:43
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 19, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 2, 2026
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 Bot added a commit that referenced this pull request Sep 2, 2026
Backport #110590 to 26.6: Validate the JSON/Object shared-data bucket count read from a stream
Avogar added a commit that referenced this pull request Sep 3, 2026
Backport #110590 to 26.3: Validate the JSON/Object shared-data bucket count read from a stream
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
Manual backport of the guard added in ClickHouse#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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…mLogEntryTask destructors

Both tasks hold a `zero_copy_lock` (a `ZeroCopyLock` wrapping a
`zkutil::ZooKeeperLock`) while performing a replicated mutation/merge with
`allow_remote_fs_zero_copy_replication` enabled. The lock is released
explicitly in `prepare()`/`finalize()` on the normal paths, but if the task
is destroyed while still holding the lock -- e.g. on cancellation before
that explicit unlock is reached -- the implicit destructor chain
(`~MutateFromLogEntryTask`/`~MergeFromLogEntryTask` -> `~ZeroCopyLock` ->
`~ZooKeeperLock` -> `unlock()`) issues a real ZooKeeper request to remove
the lock's ephemeral node.

That destructor chain runs from `MergeTreeBackgroundExecutor::routine`'s
generic task cleanup, which has no Keeper component scope set. With
`enforce_keeper_component_tracking=1` (as in integration tests and debug/
sanitizer builds), the request throws `LOGICAL_ERROR: Current component is
empty, please set it for your scope using Coordination::setCurrentComponent`,
which aborts the server.

Add an explicit destructor to each task that resets `zero_copy_lock` under
a `Coordination::setCurrentComponent` guard, following the precedent of
`DDLWorker::shutdown` explicitly clearing `active_node_holders` under a
guard rather than putting the guard in the shared, generic
`ZooKeeperLock`/`ZeroCopyLock` destructor itself.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110590&sha=5695f5662ad462d511ecdd527cbfefcd51f46a37&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29
Related: ClickHouse#110590
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Address review (AI-review Major on ClickHouse#110590): the previous commits only closed
the malformed-count bug for `Dynamic`. `SerializationObject::deserializeObjectStructureStatePrefix`
still read the `flattened_paths` / `dynamic_paths` counts straight from an
untrusted `Native` stream and passed them to `resize`, so a corrupted `JSON` /
`Object` block near `SIZE_MAX` could still throw an uncaught `std::length_error`
instead of a normal `DB::Exception`.

Translate the `std::length_error` from those `resize` calls (and the nearby
`shared_data_paths_statistics.reserve`) into a catchable `INCORRECT_DATA` error,
mirroring the `Dynamic` fix.

Add `04350_json_native_too_many_paths`, a companion to
`04307_dynamic_flattened_too_many_types`, exercising both the `FLATTENED` and
the non-flat path-count sites with hand-crafted corrupted `Native` fixtures.

Update the `Native` format specification with the normative "malformed counts"
contract for both `Dynamic` and `JSON`/`Object`.
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…y-tests-to-public

Add stateless tests ported from the Cloud-only test suite
protomn pushed a commit to protomn/ClickHouse that referenced this pull request Sep 16, 2026
…ative

`SerializationObject::deserializeObjectStructureStatePrefix` validates the V3
`shared_data_buckets` count read from the stream, but the only coverage is the gtest
`ObjectSerialization.InvalidNumberOfSharedDataBuckets`, which drives the serialization
directly rather than the `Native` reader.

Add a stateless test that feeds crafted `Native` blocks through `format` and asserts the
error code for each corner of the guard: `0`, `SIZE_MAX` and `257` are rejected as
`INCORRECT_DATA`, while `256` - the maximum - passes the guard and fails only on the
truncated payload. The structure is passed to `format` explicitly, otherwise schema
inference wraps the error and the query reports `CANNOT_EXTRACT_TABLE_STRUCTURE` instead.

The guard itself landed in ClickHouse#110590.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
PROTO: a V3 JSON/Object structure prefix read from a stream (Native input, the format() table function, a corrupted
part) with a shared-data bucket count outside 1..256 -> the count sizes the per-bucket reader state unchecked.
Effect in the production build a394e92: the backport's test 05059_json_native_invalid_shared_data_buckets kills
the server (SIGABRT in collectSharedDataFromBuckets for a bucket count of 0, from one SELECT over format('Native',
...)) and passes on official 26.8.8.8, run on isolated servers (evidence/fix_ci_20260925/upstream_repro/corrected3/).
The 26.3 backport takes only this guard from ClickHouse#110590 (a port of Cloud-only tests with several fixes); the other count
guards of ClickHouse#110590 are backported separately. Its upstream test 03057_private_attach_disk_web reads a public S3 web
disk and is no evidence either way.
Upstream patch unchanged, with its test: 05059_json_native_invalid_shared_data_buckets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
bytehalo-infra added a commit to sentioxyz/ClickHouse that referenced this pull request Sep 25, 2026
… topology check for the open GROUP BY defect

- stateless_tests.txt: +77 tests of the third batch and 10319 (13 pyarrow tests run outside the gate).
- known_defects.json: +64 KD-UP entries (fixed, each naming its commit), now 145 entries, 1 open.
  Three entries use the tests their 26.3 backports carry instead of the upstream tests the triage had used:
  ClickHouse#108728 (26.3 has no CREATE OR REPLACE MATERIALIZED VIEW; 04492_create_or_replace_table_as_select_keeps_merges),
  ClickHouse#110590 (05059 aborts the production server; 04307/04350 with the separately backported guards; 03057 is external),
  ClickHouse#117536 (05055 and the fork test 10319; upstream 04401 also needs ClickHouse#108465).
- KD-D512-MIXED-GROUPBY-NULLABLE stays open; its decision records the isolated validation of the replica-group
  upgrade topology and the rules it needs. It is not a rollout approval.
- tools/replication/upgrade_topology_check.sh: that validation, vendored from the skill draft.
- tools/upstream/triage_server_tests.py: a row whose test came from the upstream PR (the backport does not carry it)
  is classed `...-upstream-test` (a lead to review, not evidence); https URLs and web disks count as external.
- VENDORED.sha256 and README (selection count, the mandatory mixed-version GROUP BY release check - the text still
  said it was not part of the gate - and the two tools).

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

pr-bugfix Pull request with bugfix, not backported by default 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