Skip to content

Reject repeated paths in serialized states of mergedJSONPatch - #131792

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-merged-json-patch-duplicate-paths
Nov 17, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-merged-json-patch-duplicate-paths

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

A serialized state of mergedJSONPatch could contain the same path several times: insertBatchAtomic compares the entries of a batch only with the entries that existed before. insertResultInto then inserted every copy into the column of the path while adding one row to the JSON column, so the subcolumns got different sizes and later functions read out of bounds. serialize writes the paths sorted and without duplicates, so reject a state whose paths are not strictly increasing with INCORRECT_DATA.

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 a state of mergedJSONPatch containing a repeated path. Now such a state is rejected with INCORRECT_DATA.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.2533-master (included in 26.11 and later)
  • Backported to: 26.10.5.51, 26.9.31.16, 26.8.39.15

A serialized state of `mergedJSONPatch` could contain the same path several times: `insertBatchAtomic` compares the entries of a batch only with the entries that existed before. `insertResultInto` then inserted every copy into the column of the path while adding one row to the `JSON` column, so the subcolumns got different sizes and later functions read out of bounds. `serialize` writes the paths sorted and without duplicates, so reject a state whose paths are not strictly increasing with `INCORRECT_DATA`.

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 [22c53a5]

Summary: ✅


AI Review

Summary

The PR rejects duplicate or out-of-order paths in serialized mergedJSONPatch states before they can produce inconsistent JSON subcolumns, and removes preallocation based on an untrusted entry count. Reviewed the current diff, state producers, deserialization, merging, and result materialization. No actionable findings.

Missing context / blind spots
  • ⚠️ CI for head 22c53a5a4185a07b2e8ce39084d7704b1382e469 is still in progress, and no local build is available. The targeted ASan regression passed on 2e1fab66729fa33046e440329ef660e7bfda6475; the added oversized-count case still needs its current-head CI result.
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
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 22c53a5a4 with master 4553bee2f (stripped binary size, per-symbol sizes and ThinLTO time; 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.

Object file sizes

3 object files changed (+16.15 KiB total), 0 added.

Object file Master PR Δ
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionMergedJSONPat… 2.45 MiB 2.47 MiB +16.16 KiB (+0.64%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). label Nov 15, 2026

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

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 16, 2026
Merged via the queue into master with commit 571452c Nov 17, 2026
193 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-merged-json-patch-duplicate-paths branch November 17, 2026 04:49
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 17, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131792 to 26.9: Reject repeated paths in serialized states of `mergedJSONPatch`
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131792 to 26.10: Reject repeated paths in serialized states of `mergedJSONPatch`
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #131792 to 26.8: Reject repeated paths in serialized states of `mergedJSONPatch`
mkmkme pushed a commit to Altinity/ClickHouse that referenced this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). 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

Development

Successfully merging this pull request may close these issues.

4 participants