Skip to content

Revert "Revert "Feat: A SQL function obfuscateQuery"" - #101027

Merged
alexey-milovidov merged 21 commits into
masterfrom
revert-100711-revert-98305-master
Apr 27, 2026
Merged

alexey-milovidov merged 21 commits into
masterfrom
revert-100711-revert-98305-master

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 28, 2026 •

Copy link
Copy Markdown
Member

Reverts #100711, re-introducing the SQL functions obfuscateQuery and obfuscateQueryWithSeed, with additional fixes:

  • Fix buffer underread in obfuscateIdentifier for short identifiers.
  • Fix assertion failure in obfuscateQueries when a numeric literal overflows UInt64 to zero.

Changelog category (leave one):

  • Improvement

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

Added SQL functions obfuscateQuery and obfuscateQueryWithSeed that obfuscate a SQL query string by replacing identifiers and literals with randomized placeholders while preserving the query structure. Fixed edge cases in query obfuscation for short identifiers and oversized integer literals.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Backported to: 26.4.2.7

@clickhouse-gh

clickhouse-gh Bot commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3e663cf]

Summary: ✅


AI Review

Summary

This PR re-introduces obfuscateQuery and obfuscateQueryWithSeed, fixes a buffer underread in obfuscateIdentifier, and fixes the overflow-to-zero assertion path in numeric literal obfuscation, with corresponding stateless regression coverage. I did not find additional correctness, safety, performance, or ClickHouse-compliance issues in the current diff.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Mar 28, 2026

}

REGISTER_FUNCTION(obfuscateQuery)

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.

The PR body does not follow .github/PULL_REQUEST_TEMPLATE.md: Changelog category and Changelog entry are missing. Since this PR re-introduces user-facing SQL functions (obfuscateQuery / obfuscateQueryWithSeed), please fill template metadata with a concrete user-readable changelog entry.

The ASan crash (stack-buffer-overflow) was caused by accessing
`src_pos[-1]` on the first character of the identifier in the CamelCase
split logic. For input like `'Ab'`, the first character `'A'` is
uppercase and alphanumeric, so `word_has_alphanumerics` is true, and the
code tried to check whether the previous character is lowercase — but
there is no previous character, reading one byte before the buffer.

Fix: add a bounds check `src_pos > src.data()` before the `src_pos[-1]`
access.

https://s3.amazonaws.com/clickhouse-test-reports/PRs/100683/14d36b8a2b692110d6a5f5eb898d4a37a3a612ca/unit_tests_asan_ubsan/job.log

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@alexey-milovidov
alexey-milovidov marked this pull request as ready for review March 28, 2026 19:08

obfuscated = (1ULL << log2) + obfuscated % (1ULL << log2);
writeIntText(obfuscated, result);
if (num == 0)

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.

⚠️ This change adds a dedicated overflow path when readIntText overflows to num == 0, but there is no regression test covering it.

Please add a stateless test that exercises a very large integer literal (larger than UInt64) through obfuscateQueryWithSeed to lock this behavior and prevent regressions in this branch.

alexey-milovidov and others added 2 commits March 30, 2026 03:46
Exercise the code path where `readIntText` overflows `uint64_t` to zero
for very large numeric literals, as requested in review feedback.

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

Copy link
Copy Markdown
Member Author

The test 02859_replicated_db_name_zookeeper is fixed in #101952

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Apr 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 93.44% (171/183) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov self-assigned this Apr 27, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 27, 2026
Merged via the queue into master with commit 5a531ec Apr 27, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the revert-100711-revert-98305-master branch April 27, 2026 05:28
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 27, 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 May 6, 2026
robot-ch-test-poll1 added a commit that referenced this pull request May 6, 2026
Cherry pick #101027 to 26.4: Revert "Revert "Feat: A SQL function obfuscateQuery""
@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 May 6, 2026
alexey-milovidov added a commit that referenced this pull request May 6, 2026
Backport #101027 to 26.4: Revert "Revert "Feat: A SQL function obfuscateQuery""
pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Jun 6, 2026
…-4165)

A `BackgroundJobsAssignee` task on a pool thread can race with
`~StorageMergeTree` / `~StorageReplicatedMergeTree` and dispatch
`data.scheduleDataProcessingJob(*this)` through a vtable that has already
demoted to `MergeTreeData`. `scheduleDataProcessingJob` is pure virtual
at the `MergeTreeData` level (only the leaf storages override it), so
the dispatch lands on `__cxa_pure_virtual` and aborts the server.

This is reachable in practice when `shutdown` throws partway through
the cleanup. `StorageReplicatedMergeTree::~StorageReplicatedMergeTree`
wraps the `shutdown` call in a try/catch and swallows the exception, so
member destruction proceeds with the background scheduler still alive.
`~BackgroundJobsAssignee::finish()` then calls `deactivate()`, which
blocks on `exec_mutex` waiting for the in-flight `threadFunc` to finish
— but `threadFunc`'s next call is the pure-virtual dispatch above.

The fix is a defensive `false`-returning override of
`scheduleDataProcessingJob` on `MergeTreeData`. In normal operation,
the derived overrides win the virtual dispatch and this default is
dead code. During the destruction race, the default takes the dispatch:
`threadFunc` reads `false` as "no work scheduled" and falls through to
`postpone()`, which is a no-op once `finish()` has moved the holder
out. The pool thread completes `execute()` normally, the destructor's
`deactivate()` returns, and destruction proceeds safely.

Affected runs (all identical stack traces, all unrelated PRs):
- PR ClickHouse#102343 (Paimon) — Stress test (arm_asan_ubsan)
- PR ClickHouse#101027 (obfuscateQuery revert) — Stress test (arm_asan_ubsan, s3)
- PR ClickHouse#100272 (h3 → h3o) — Stress test (arm_asan_ubsan, s3)
- PR ClickHouse#104472 (count_distinct_optimization) — Stress test (arm_debug)

CI report (latest):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104472&sha=ad31d65c8cb512098dc41a848bfa9e42650e123e&name_0=PR&name_1=Stress%20test%20%28arm_debug%29

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…1027

Backport ClickHouse#101027 to 26.4: Revert "Revert "Feat: A SQL function obfuscateQuery""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements 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 v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants