Repository navigation
Do not use the client output format after a failed initialization destroyed its buffer - #127912
Conversation
…troyed its buffer `ClientBase::initOutputFormat` creates `output_format` over `std_out_wrapper` (or `out_file_buf`), and the format keeps a reference to that buffer. For a binary format on a terminal it then asks whether to output it anyway. In the web terminal, closing the session closes the PTY, the read of the answer fails with EIO, and the `catch` destroyed `out_file_buf` and `std_out_wrapper` while keeping `output_format`. `receiveResult` continues after the `LocalFormatError`, and `resetOutput` then finalized the format into the freed buffer: a heap use-after-free (ASan), use-of-uninitialized-value (MSan) and SIGSEGV (debug) in Stress tests since they run queries over the web terminal (ClickHouse#125517). Destroy the format first in that `catch`, before the buffers it writes into (the same order as `resetOutput`). A failure after the format was created now leaves the same state as a failure before it (ClickHouse#93298), and the next result packet creates the format again. The new test opens a web terminal session, runs a `RowBinary` query, waits for the question and closes the connection; the server must stay alive. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 runs on the same code, the second after a PR description edit; 3 distinct findings, all nits, none on the code or the test).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261027-041500 |
|
cc @alexey-milovidov @azat, could you review this and add the |
|
Workflow [PR], commit [0ecac9e] Summary: ❌
AI ReviewSummaryPR #127912 fixes a use-after-free when output-format initialization fails by destroying Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; let sanitizer CI and bugfix validation complete before merging. |
CI finish ledger - 0ecac9eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The first run of this head stopped at Session id: cron:our-pr-ci-monitor:20261027-203012 |
956f38d
…cts the readiness probe for load Since 2026-10-26 18:19 UTC the read-only sub-service of the CI logs cluster answers every query, including the `SELECT 1` readiness probe and before authentication, with `Code: 241` (`(total) memory limit exceeded: would use 213.20 GiB ... maximum: 212.40 GiB`). `select` classifies 241 as `LogClusterUnavailable` (green check), but `is_ready` threw the answer away, so every read ended with `LogClusterNotReady` and the check was ERROR in practically every PR. `is_ready` now logs the status and body of a failed probe and, when the server itself answered (the `X-ClickHouse-Exception-Code` header is present), keeps its classification. If no POST was attempted and the last probe was rejected for load (202, 241), `select` raises `LogClusterUnavailable`. A missing secret, no connection, a gateway answer, or any other exception code (516 for a rotated password) still raise `LogClusterNotReady`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127912&sha=0ecac9e802642ebf566075f5145796c9db1fde22&name_0=PR&name_1=Build%20profile%20diff Related: ClickHouse#127912 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lient After a `LocalFormatError` (the client failed to create or write its output format), `receiveResult` sends `Cancel` but kept passing every remaining `Data` / `Totals` / `Extremes` packet to `onData` / `onTotals` / `onExtremes`. When the error came from `initOutputFormat`, `output_format` is null afterwards, so every remaining block built the output again: the pager was started again, the `INTO OUTFILE` file was opened again, and a failure that went away mid-result left an output with a gap while the client still exited with the first error. Since ClickHouse#127912 the binary-format question is asked again too, reading the stdin the first failed answer canceled (`LOGICAL_ERROR 'ReadBuffer is canceled'`, STID 2508-2bbd on master). A per-query flag is set where a `LocalFormatError` is created (the three sites: `initOutputFormat`, the write in `onData`, the background error check in `receiveResult`), checked at the top of the three result callbacks, and reset in `processParsedSingleQuery`. Setting it at the origins instead of in `receiveResult` also covers the `INSERT ... RETURNING` drain (`receiveEndOfQueryForInsert` calls the callbacks directly). `cancelled` is not reused: it would disable the receive timeout and Ctrl+C handling in the drain loop, skip waiting for the pager and print "Query was cancelled.". Requested by @PedroTadim in ClickHouse#128090 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #93298
Related: #125517
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a possible server crash (use-after-free) when a web terminal session is closed while the client asks whether to output a binary format such as
RowBinary.Description
On 26.10.2.103-stable, closing a web terminal session while the client asks
Do you want to output it anyway? [y/N]for a binary format (SELECT 1 FORMAT RowBinary) makes the server read a freed buffer: the ASan build of that tag reportsheap-use-after-free. Since the Stress test runs queries over the web terminal (#125517), this crashed the server on master, release build included: Stress test (arm_release) and Stress test (amd_debug) (SIGSEGV), Stress test (amd_msan) (use-of-uninitialized-value).The format created in
ClientBase::initOutputFormatrefers tostd_out_wrapper(orout_file_buf). When the session closes, the read of the answer inaskfails withEIO, and thecatchofinitOutputFormatdestroys both buffers but keepsoutput_format. The client keeps receiving the result, andresetOutputfinalizes the format into the freed buffer.The
catchnow destroys the format first, so a failure after the format was created leaves the same state as a failure before it.The new test waits for the question and closes the WebSocket. Without the fix the ASan server aborts with the CI stack 10/10 times; with it the test passes 50/50 with random settings, and
RowBinary,BSONEachRow,ParquetandNativeno longer abort it. #126142 is a different defect inresetOutput.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127912]
Version info
26.11.1.852-master(included in26.11and later)