Skip to content

Reject repeated paths in a serialized value of JSON in aggregate states - #131791

Merged
Avogar merged 3 commits into
masterfrom
fix-json-aggregate-state-duplicate-paths
Nov 19, 2026
Merged

Avogar merged 3 commits into
masterfrom
fix-json-aggregate-state-duplicate-paths

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Closes: #132739

A value of a JSON column in an aggregate state (for example of groupArray) is deserialized by ColumnObject::deserializeDynamicPathsAndSharedDataFromArena, which accepted a path repeated within a row. A repeated dynamic path got several values for one row, so the column of the path became longer than the JSON column, and functions using it (getNumberOfDefaultRows, for example) read and wrote out of bounds. Reject a repeated dynamic path and shared-data paths that are not strictly increasing with INCORRECT_DATA, the way they are serialized, and check that subcolumns have the size of the column in ColumnObject::getNumberOfDefaultRows.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix out-of-bounds memory access with an aggregate state containing a JSON value with a repeated path. Now such a state is rejected with INCORRECT_DATA.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.2877-master (included in 26.11 and later)
  • Backported to: 26.10.8.31, 26.9.34.11, 26.8.42.18, 26.3.67.30

…ates

A value of a `JSON` column in an aggregate state (for example of `groupArray`) is deserialized by `ColumnObject::deserializeDynamicPathsAndSharedDataFromArena`, which accepted a path repeated within a row. A repeated dynamic path got several values for one row, so the column of the path became longer than the `JSON` column, and functions using it (`getNumberOfDefaultRows`, for example) read and wrote out of bounds. Reject a repeated dynamic path and shared-data paths that are not strictly increasing with `INCORRECT_DATA`, the way they are serialized, and check that subcolumns have the size of the column in `ColumnObject::getNumberOfDefaultRows`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c65f88b]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) FAIL
Cannot list the mutations left unfinished by the stress phase FAIL cidb
Cannot count the mutations left unfinished by the stress phase FAIL cidb
Cannot run the mutation entries left behind by the killed mutations (see undrained_mutation_errors.txt) FAIL cidb
Cannot submit the mutation that has to survive the upgrade FAIL cidb
Cannot list the row policies left by the stress phase FAIL cidb
Error message in clickhouse-server.log (see upgrade_error_messages.txt) FAIL cidb
Logical error: Context has expired (STID: 1805-3f9b) FAIL cidb

AI Review

Summary

Reviewed PR #131791 at c65f88beb26409e900c7886f0a3361510ed091cb. The change rejects duplicate dynamic paths, duplicate or unordered shared-data paths, and collisions with typed paths when reading serialized JSON aggregate values, and guards ColumnObject::getNumberOfDefaultRows against inconsistent subcolumn sizes. The earlier typed-path finding is fixed; no outstanding findings remain. The new stateless regression passed in CI. Twenty focused checks using this revision's fast-test binary also succeeded: eight valid cases preserved their values and twelve malformed cases were rejected, covering mixed storage, multiple rows, duplicates, ordering, null values, and truncation.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Nov 15, 2026
Comment thread src/Columns/ColumnObject.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c65f88beb with master 9005321e3 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of e4cde4748; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-json-datatype JSON/Dynamic/Object datatype: semi-structured column storage, typed and dynamic paths, sub-object... label Nov 15, 2026
Address review: `deserializeAndInsertFromArena` inserts typed paths before
`deserializeDynamicPathsAndSharedDataFromArena`, so a name of a typed path
repeated in the dynamic part passed both checks and got a second value in a
new dynamic path or in shared data. Reject it with `INCORRECT_DATA` and add
both cases to the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Avogar Avogar assigned Avogar and unassigned alexey-milovidov Nov 16, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure of 05409_quota_on_profile_events_remote_insert_mv_dedup (flaky; it also failed in #117170 on 2026-11-10): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131791&sha=65606d31cfb955af7dd127781c6f48992bd12a6b&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20AsyncInsert%2C%20s3%20storage%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The Upgrade check (amd_release) failure (Logical error: Context has expired in FunctionKQLMultiply) comes from the old 26.10 binary. It is fixed on master by #131363, and the backport #132081 is open.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. I'm investigating the 05409_quota_on_profile_events_remote_insert_mv_dedup failure (AsyncInsert and ParallelReplicas lanes); I'll follow up here with a fixing PR (or my findings) shortly. No fix for it is in progress yet.

@clickhouse-gh clickhouse-gh Bot left a comment

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.

AI review approves this commit, see the AI Review comment.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is #132139 (test-only).

Both failures (AsyncInsert and ParallelReplicas jobs) have one cause: the randomized merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability is forwarded with the INSERT to the remote servers, and when it splits the view's dim_05409 read into layers, the granule on each layer border is read by both layers. SelectedRows then grows by one granule (116 or 110 instead of 108). The PR clamps that setting to 0 in the test header, the same clamp #129987 added to 05508.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks, @groeneai — #132139 covers the flaky 05409_quota_on_profile_events_remote_insert_mv_dedup. That leaves one CI failure on the head commit, Upgrade check (amd_release). It comes from the old 26.10 binary (Context has expired in kqlMultiply), which #131363 fixes on master, and its backport #132081 is still open. Neither failure is caused by this PR.

qoega pushed a commit to qoega/ClickHouse that referenced this pull request Nov 19, 2026
The second section asserts the exact `SelectedRows` quota charge (108) of a
distributed `INSERT` whose materialized view on the remote server reads
`dim_05409` (100 rows) through `remote`. CI got 116 and 110 on two PRs, both
in `arm_binary ... s3 storage, parallel` jobs.

The randomized `merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability`
is forwarded with the `INSERT` to the remote servers. When the coin fires on a
read with more than one stream, `ReadFromMergeTree::spreadMarkRangesAmongStreams`
splits the ranges into layers with `splitPartsWithRangesByPrimaryKey`, and the
granule on a layer border is read by both pipes (the PK-boundary filter drops
the duplicates, so the result is right). `SelectedRows` counts that granule
twice: +8 at `index_granularity` 8 (116), +2 at `index_granularity` 1 (110).
A 100-row part gets several streams on object storage, where the
concurrent-read thresholds are 0, which is why only the s3 jobs failed.

Clamp the injection to 0 for this test with the runner's per-setting limit,
the same header as 05508 (ClickHouse#129987). Every other setting stays randomized.

Related: ClickHouse#131791

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Avogar

Avogar commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Upgrade check was fixed in #132081

@Avogar
Avogar added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit d3cf64c Nov 19, 2026
191 of 193 checks passed
@Avogar
Avogar deleted the fix-json-aggregate-state-duplicate-paths branch November 19, 2026 19:07
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 19, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 19, 2026
robot-ch-test-poll2 added a commit that referenced this pull request Nov 19, 2026
Cherry pick #131791 to 26.3: Reject repeated paths in a serialized value of `JSON` in aggregate states
robot-clickhouse added a commit that referenced this pull request Nov 19, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 19, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 19, 2026
Backport #131791 to 26.10: Reject repeated paths in a serialized value of `JSON` in aggregate states
clickhouse-gh Bot added a commit that referenced this pull request Nov 19, 2026
Backport #131791 to 26.9: Reject repeated paths in a serialized value of `JSON` in aggregate states
alexey-milovidov added a commit that referenced this pull request Nov 20, 2026
Backport #131791 to 26.3: Reject repeated paths in a serialized value of `JSON` in aggregate states
nikitamikhaylov added a commit that referenced this pull request Nov 20, 2026
Backport #131791 to 26.8: Reject repeated paths in a serialized value of `JSON` in aggregate states
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-json-datatype JSON/Dynamic/Object datatype: semi-structured column storage, typed and dynamic paths, sub-object... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix 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

5 participants