Repository navigation
Fix abort on malformed uniqTheta state in ThetaSketchData::read - #106260
Algunenano merged 2 commits into
Conversation
Deserializing a malformed AggregateFunction(uniqTheta, ...) state used to throw std::out_of_range / std::invalid_argument from the third-party datasketches library. Those are not DB::Exception, so they escaped the catch (...) block in SerializationAggregateFunction (which rethrows by type) and ReplaceQueryParameterVisitor (which only catches DB::Exception). At the top level a bare std::exception is treated as LOGICAL_ERROR (code 1001), and abortOnFailedAssertion aborts the process with SIGABRT. Wrap the datasketches::compact_theta_sketch::deserialize call at the library boundary in ThetaSketchData::read with a try / catch block that re-throws DB::Exception unchanged and translates bare std::exception to DB::Exception(CORRUPTED_DATA). Both the RowBinary deserializeBinary path and the query-parameter deserializeTextEscaped path go through this read, so a single boundary catches both fuzzer-found code paths. Adds a stateless regression test 04307_uniqTheta_corrupted_state_106259 covering both code paths with the 24-byte payload from the issue. Closes ClickHouse#106259
|
Pre-PR validation gate (TASK.md Phase 4 Step 9): (a) Deterministic repro? Yes. (b) Root cause explained? Yes. The 3-byte sketch payload is shorter than the Theta sketch minimum, so (c) Fix matches root cause? Yes. The translation happens at the third-party library boundary in (d) Test intent preserved / new tests added? Yes. New stateless test (e) Both directions demonstrated? Yes:
(f) Fix is general, not a narrow patch? Yes. The fix is at the only ClickHouse call site into Session: |
|
cc @qoega for the directive. The fix translates the |
|
Workflow [PR], commit [f9394fc] Summary: ❌
AI ReviewSummaryThis PR fixes malformed Missing context / blind spots
Final VerdictStatus: ✅ Approve |
The previous commit translated every std::exception from
`compact_theta_sketch::deserialize` into `CORRUPTED_DATA`. The
`std::exception` base also covers `std::bad_alloc` from internal
allocations in `deserialize`, `getSkUnion`, or `theta_union.update`,
so a valid large state or a memory-pressure failure would have been
mis-reported as data corruption.
Add a `catch (const std::bad_alloc &) { throw; }` arm before the
catch-all so allocation failures propagate as allocation failures.
Malformed-input paths still throw `std::invalid_argument` /
`std::out_of_range`, which the catch-all keeps translating to
`CORRUPTED_DATA`. The existing regression test
`04307_uniqTheta_corrupted_state_106259.sh` still passes for both
the RowBinary and query-parameter paths.
Addresses clickhouse-gh[bot] inline review on
ClickHouse#106260
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 14/16 (87.50%) | Lost baseline coverage: none · Uncovered code |
|
CI finished on f9394fc. The only test-level failure is unrelated to this PR:
All other 144 checks pass. The fix + regression test ( |
Algunenano
left a comment
There was a problem hiding this comment.
Looks good:
Code: 1001. DB::Exception: std::out_of_range: at least 8 bytes expected, actual 3. (STD_EXCEPTION)
Code: 246. DB::Exception: Cannot deserialize Theta sketch state: at least 8 bytes expected, actual 3: (in file/uri (fd = 0)): While executing BinaryRowInputFormat: While executing File. (CORRUPTED_DATA)
Not something we need to backport, it only affected debug releases
c0b4d93
|
@alexey-milovidov, could you add On 26.3, This PR applies cleanly to the current 26.3 (three-way merge of |
…ead` The backported test `05215_uniq_theta_short_state` feeds states that `datasketches` refuses with `std::invalid_argument` (`seed hash mismatch`). On 26.3 that exception was not translated, so it reached the top level as `LOGICAL_ERROR` and aborted the sanitizer build in the stress test. Bring in the translation to `CORRUPTED_DATA` from #106260, which the original change relied on. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=123773&sha=4636b5a69c3dfbb9110b7660ee1461d8f6cdf5d4&name_0=BackportPR&name_1=Stress%20test%20%28amd_tsan%29 PR: #123773 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The
datasketcheslibrary throwsstd::out_of_range/std::invalid_argumentwhen deserialising malformed Theta sketch bytes. Those are notDB::Exception, so they escapeSerializationAggregateFunction'scatch (...)block (which rethrows by type) andReplaceQueryParameterVisitor(catch (Exception &)). At the top level a barestd::logic_errorsubclass triggers an unconditionalabortOnFailedAssertionandSIGABRT, in both debug and release builds.Wrap the
datasketches::compact_theta_sketch::deserializecall at the library boundary inThetaSketchData::readwith atry/catchblock that rethrowsDB::Exceptionunchanged and translates barestd::exceptiontoDB::Exception(CORRUPTED_DATA). Both theRowBinarydeserializeBinarypath and the query-parameterdeserializeTextEscapedpath go through thisread, so a single boundary catches both fuzzer-found code paths.Adds stateless regression test
04307_uniqTheta_corrupted_state_106259covering both code paths with the 24-byte payload from the issue.Closes #106259
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an abort when deserialising a malformed
AggregateFunction(uniqTheta, ...)state fromRowBinaryinput or a query parameter. The bad input is now rejected withCORRUPTED_DATAinstead of escaping as astd::exceptionand aborting the process viaabortOnFailedAssertion.Documentation entry for user-facing changes
Version info
26.6.1.495