Repository navigation
Revert "Revert "Feat: A SQL function obfuscateQuery"" - #101027
Conversation
|
Workflow [PR], commit [3e663cf] Summary: ✅ AI ReviewSummaryThis PR re-introduces ClickHouse Rules
Final VerdictStatus: ✅ Approve |
|
|
||
| } | ||
|
|
||
| REGISTER_FUNCTION(obfuscateQuery) |
There was a problem hiding this comment.
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]>
…flows to zero `readIntText` can overflow a `uint64_t` for very large numeric literals, resulting in `num == 0`. This then calls `bitScanReverse(0)` which triggers `assert(x != 0)` in debug builds. Handle the overflow case by using the obfuscated hash directly. Found by the AST fuzzer in CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101027&sha=f9d39a5d7a9cd9d194db7593f4a84a0ebfd15e05&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
|
||
| obfuscated = (1ULL << log2) + obfuscated % (1ULL << log2); | ||
| writeIntText(obfuscated, result); | ||
| if (num == 0) |
There was a problem hiding this comment.
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.
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]>
|
The test |
LLVM Coverage Report
Changed lines: 93.44% (171/183) · Uncovered code |
Cherry pick #101027 to 26.4: Revert "Revert "Feat: A SQL function obfuscateQuery""
Backport #101027 to 26.4: Revert "Revert "Feat: A SQL function obfuscateQuery""
…-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]>
…ion obfuscateQuery""
…1027 Backport ClickHouse#101027 to 26.4: Revert "Revert "Feat: A SQL function obfuscateQuery""
Reverts #100711, re-introducing the SQL functions
obfuscateQueryandobfuscateQueryWithSeed, with additional fixes:obfuscateIdentifierfor short identifiers.obfuscateQuerieswhen a numeric literal overflowsUInt64to zero.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added SQL functions
obfuscateQueryandobfuscateQueryWithSeedthat 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
Version info
26.4.2.7