Repository navigation
Validate UTF-8 of DeltaLake delta-kernel-rs FFI option values - #105897
Conversation
The `delta-kernel-rs` Rust FFI decodes `KernelStringSlice` payloads as
`&str` via `std::str::from_utf8` and panics on invalid UTF-8. A panic
crossing the `extern "C"` boundary aborts the server through
`panic_in_cleanup`. Binary credentials (for example raw `MD5(...)` bytes
passed as a SAS token) trip this and crash a debug or sanitizer build.
Wrap `ffi::set_builder_option` with a C++ side check that runs the value
bytes through `DB::UTF8::isValidUTF8` first and throws `BAD_ARGUMENTS`
when the bytes are not valid UTF-8. The lambdas in `S3KernelHelper` and
`AzureKernelHelper` now route through the wrapper, so any user supplied
credential, region, endpoint or SAS token is validated before reaching
the FFI boundary.
Adds regression test `04294_deltalake_azure_invalid_utf8_credentials`
covering the reproducer `SELECT * FROM deltaLakeAzure('\0', MD5(''))`
from issue ClickHouse#105895.
Closes ClickHouse#104509
Closes ClickHouse#105895
Pre-PR validation gate (mandatory per TASK.md Phase 4 Step 9)a) Deterministic repro? Yes. b) Root cause explained? Yes. The c) Fix matches root cause? Yes. The fix wraps d) Test intent preserved? / New tests added? Yes. Added regression test e) Both directions demonstrated? Yes. Without the fix: reproduced SIGABRT with a stack trace ending in f) Fix is general, not a narrow patch? Yes. Both Session: cron:clickhouse-ci-task-worker:20260526-193000. |
|
cc @kssenii @alesapin @SmitaRKulkarni - could you review? Fixes a server abort when a deltaLake table function receives a non-UTF-8 credential value (e.g. raw MD5 bytes as a SAS token); validates the bytes on the C++ side of the delta-kernel-rs FFI and returns BAD_ARGUMENTS instead of letting the Rust panic cross the extern "C" boundary. Closes #104509 / #105895. |
|
Workflow [PR], commit [13380c2] Summary: ⏳
AI ReviewSummaryThis PR adds a UTF-8 validation guard before calling Final Verdict
|
LLVM Coverage Report
Changed lines: 100.00% (13/13) · Uncovered code |
|
@groeneai check the failing test |
Algunenano
left a comment
There was a problem hiding this comment.
This covers the exposed argument with a proper error, which is great.
In the future we should consider working on delta-kernel-rs (our fork and upstream) to add catch_unwind to every pub unsafe extern "C" fn body in ffi/src/, which would have prevented this and future issues. Also, replacing unwrap (hello Cloudflare) with proper ExternResult / Option::None returns.
The previous .sql regression used `{ serverError BAD_ARGUMENTS }`, which
expects the query to return that error code. On the unfixed master binary
the query does not return an error: it crashes the process via the
`delta-kernel-rs` Rust panic in `set_builder_option`. `clickhouse-test`
detects the death and raises `StopTesting` before recording a per-test
`FAIL`, so the Bugfix validation framework sees no individual failure and
reports `Failed to reproduce the bug`.
Switch to a `.sh` test modelled on `03003_prql_panic.sh` that runs the
query through `clickhouse-local` and greps stderr for `BAD_ARGUMENTS`.
On the unfixed binary the process crashes and stderr contains only the
Rust panic backtrace, so grep produces empty output that does not match
the new reference, yielding a clean test `FAIL`. On the fixed binary the
query throws `BAD_ARGUMENTS` and grep matches it, yielding a `PASS`.
Because the test invokes `clickhouse-local` rather than the connected
server, the crash does not poison the live server, so `clickhouse-test`
does not flag `SERVER_DIED` and Bugfix validation proceeds normally.
Verified locally: on the current master binary (no fix), the new test
produces empty stdout and exit code 1 from the grep pipeline, which
mismatches the new `BAD_ARGUMENTS` reference and is a clean `FAIL`.
CI: ClickHouse#105897
|
@PedroTadim the only red check is Diagnosis. Bugfix validation runs the new regression test against the unfixed master binary and expects a per-test
So the message is misleading: the bug is present and reproduced (the panic is in the validation job's Fix. Pushed
Using Verified locally against the current master binary (no fix): the new |
|
Hi — could this be a backport candidate for Affected code: Why this might apply: The delta-kernel-rs feature was introduced in January 2025 (commit 1b18fe1), which predates all supported release branches. This is a server abort bug that affects all users of Caveat: I verified that the modified code exists in those branches, but not whether the bug is actually reachable there — a new caller in master may be what makes this newly observable. If older branches can't reach the affected path, please ignore this; otherwise consider |
Cherry pick #105897 to 26.5: Validate UTF-8 of DeltaLake delta-kernel-rs FFI option values
Cherry pick #105897 to 26.4: Validate UTF-8 of DeltaLake delta-kernel-rs FFI option values
Use `gpt-5.5` for the custom AI review job instead of `gpt-5.3-codex` in both `copilot` and `codex exec`. Motivation: `gpt-5.3-codex` did not detect issues in #105897, while `gpt-5.5` does. `Claude 4.7` also detects them.
|
The second commit here landed after the PR has been approved. I do not see the full CI run with second commit.
PS: I see, already reverted. |
|
You are right about the post-approval commit. I have re-submitted the fix as #106018, this time with the leak prototyped in #105961 folded in:
The intent is that both the ASan leak (the actual revert cause) and the original abort (the original repro |
Two Rust panics could cross the `extern "C"` boundary and abort the server (issue #104509): `set_builder_option` called `.unwrap()` on invalid UTF-8, and a panic deep inside `snapshot` (for example `object_store` rejecting a credential that is valid UTF-8 but an invalid HTTP header value) reached `panic_cannot_unwind`. Bump the `delta-kernel-rs` fork so `set_builder_option` returns an error instead of panicking, add `free_engine_builder`, and guard `snapshot` and `builder_build` with `catch_unwind`. On the C++ side route option setting through `KernelUtils::unwrapResult` and free the builder with a RAII guard on the error path, which also fixes the leak introduced by the reverted PR #105897. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-kernel-rs FFI option values
…-kernel-rs FFI option values
The
delta-kernel-rsRust FFI decodesKernelStringSlicepayloads as&strvia
std::str::from_utf8and panics on invalid UTF-8. A panic that crosses theextern "C"boundary aborts the server throughpanic_in_cleanup. Binarycredentials (for example raw
MD5(...)bytes used as a SAS token) trip thisand abort a debug or sanitizer build.
SELECT * FROM deltaLakeAzure('\0', MD5('')) SETTINGS allow_experimental_delta_kernel_rs = 1deterministically reproduces the abort. The stack trace shows
set_builder_option @ ffi/src/lib.rs:488reached from theset_optionlambdain
AzureKernelHelper::createBuilder, with the offending payload being theazure_storage_sas_keyvalue populated fromMD5('').The fix wraps
ffi::set_builder_optionwith a C++ side check that runs thevalue bytes through
DB::UTF8::isValidUTF8first and throwsBAD_ARGUMENTSwhen the bytes are not valid UTF-8. The lambdas in
S3KernelHelperandAzureKernelHelperroute through the wrapper so any user supplied credential,region, endpoint or SAS token is validated before reaching the FFI boundary.
LocalKernelHelperdoes not callset_builder_optionand is not affected.Adds regression test
04294_deltalake_azure_invalid_utf8_credentialscoveringthe reproducer.
Closes #104509
Closes #105895
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reverted
Version info
26.6.1.176