Repository navigation
Conversation
Re-submits the change from PR ClickHouse#105897 ("Validate UTF-8 of DeltaLake delta-kernel-rs FFI option values"), which was merged in a07ca55 and then reverted in 3ab7b26 / PR ClickHouse#105963. The revert reason was a memory leak surfaced by ASan in the `s3 storage` stateless variant when the new `setBuilderOptionChecked` wrapper rejected an invalid-UTF-8 option: the Rust FFI does not expose a `free_engine_builder`, and the partially configured `ffi::EngineBuilder` was leaked when the wrapper threw before `ffi::builder_build` could consume it. This patch combines the original UTF-8 validation with the leak fix prototyped by @PedroTadim in PR ClickHouse#105961: * `IKernelHelper::createBuilder` is now a non-virtual base method that allocates the builder via `ffi::get_engine_builder`, calls a new protected virtual `configureBuilder` hook, and, if `configureBuilder` throws, cleans the builder up by calling `ffi::builder_build` (consumes the builder, returns an engine handle) followed by `ffi::free_engine`. The original exception is rethrown. * `S3KernelHelper` and `AzureKernelHelper` override `configureBuilder` instead of `createBuilder` and route every option through `setBuilderOptionChecked`, which rejects invalid UTF-8 with `BAD_ARGUMENTS` so it never reaches the FFI `&str` decode that panics with `panic_in_cleanup`. * `LocalKernelHelper` inherits the default empty `configureBuilder`. Its `getTableLocation` no longer appends a second `/` when the user-provided path already ends with one (also from PR ClickHouse#105961). The regression test `04294_deltalake_azure_invalid_utf8_credentials` uses the deterministic reproducer `SELECT * FROM deltaLakeAzure('\0', MD5(''))` from issue ClickHouse#105895 and is kept as a `.sh` test on purpose: the unfixed binary crashes the process, so a `.sql` test with `{ serverError BAD_ARGUMENTS }` cannot distinguish a crash from a clean error and Bugfix validation would not record a clean `FAIL` on master. With `clickhouse-local` + `grep`, the unfixed binary produces empty stdout (process abort, no `BAD_ARGUMENTS` text) and the fixed binary prints the diagnosis, so Bugfix validation works for both directions. CI leak that motivated the revert (per PR ClickHouse#105961): https://d1k2gkhrlfqv31.cloudfront.net/clickhouse-test-reports-private/json.html?PR=59140&sha=latest&name_0=PR&name_1=Stateless+tests+%28amd_asan_ubsan%2C+distributed+cache%2C+meta+in+keeper%2C+s3+storage%2C+parallel%2C+1%2F2%29 Closes ClickHouse#104509 Closes ClickHouse#105895 Co-Authored-By: Pedro Ferreira <[email protected]>
Collaborator
Author
|
Pre-PR validation gate (per worker policy, separate from the PR description):
|
Member
|
@Algunenano you give a review first before enabling testing. This looks fine for me. |
Algunenano
requested changes
May 28, 2026
Algunenano
left a comment
Member
There was a problem hiding this comment.
This PR addresses:
- set_builder_option panicking on invalid UTF-8
- The EngineBuilder leak from the original revert
This PR does not address:
- ffi::snapshot failures reported in #104509 as
Failure mode 2. - Also, it seems that the cleanup path can re-trigger the same bug
- name is not validated. Right now it's internal only, but it's one step away from being public.
I mentioned when reviewing the other PR that it was ok but we should fix this properly. That PR had to be reverted. So let's fix this properly upstream, then apply checks and proper error handling here.
@groeneai I don't think you can work with rust submodules, so I'll deal with it
Collaborator
Author
|
Acknowledged, closing. Happy to help with the C++ cleanup wrapper (createBuilder non-virtual base + try/catch + builder_build then free_engine) once the upstream delta-kernel-rs fix lands, if useful. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-submits the change from #105897 ("Validate UTF-8 of DeltaLake delta-kernel-rs FFI option values"), which was merged in
a07ca558f023and then reverted in3ab7b26f7189/ #105963.Why the original was reverted. ASan flagged a leak in the
s3 storagestateless variant: the Rust FFI does not exposefree_engine_builder, and the newsetBuilderOptionCheckedwrapper threwBAD_ARGUMENTSon the invalid-UTF-8 path beforeffi::builder_buildcould consume the partially configuredffi::EngineBuilder. The original CI leak report (per #105961):https://d1k2gkhrlfqv31.cloudfront.net/clickhouse-test-reports-private/json.html?PR=59140&sha=latest&name_0=PR&name_1=Stateless+tests+%28amd_asan_ubsan%2C+distributed+cache%2C+meta+in+keeper%2C+s3+storage%2C+parallel%2C+1%2F2%29
What changed. Combines the original UTF-8 validation with the leak fix prototyped by @PedroTadim in #105961 (closed when the revert landed):
IKernelHelper::createBuilderis now a non-virtual base method. It allocates the builder viaffi::get_engine_builder, invokes a new protected virtualconfigureBuilderhook, and, ifconfigureBuilderthrows, consumes the builder viaffi::builder_buildand frees the resulting engine viaffi::free_enginebefore rethrowing.S3KernelHelperandAzureKernelHelpernow overrideconfigureBuilderand route every option throughsetBuilderOptionChecked, which rejects invalid UTF-8 withBAD_ARGUMENTSso it never reaches the FFI&strdecode that panics withpanic_in_cleanup.LocalKernelHelperinherits the default emptyconfigureBuilderand no longer appends a second/when the user-provided path already ends with one (also from Kernel Helper fixes #105961).Test.
04294_deltalake_azure_invalid_utf8_credentialsuses the deterministic reproducerSELECT * FROM deltaLakeAzure('\0', MD5(''))from #105895. It is kept as a.shtest on purpose: the unfixed binary aborts the process, so a.sqltest with{ serverError BAD_ARGUMENTS }cannot distinguish a crash from a clean error and Bugfix validation would not record a cleanFAILon master. Withclickhouse-local+grep, the unfixed binary produces empty stdout and the fixed binary prints the diagnosis, so Bugfix validation works in both directions.cc @CheSema (your concern on the original PR about a post-approval test commit landing without a full CI run is acknowledged: this re-submission runs the new test through full CI before merge), @Algunenano (revert author), @PedroTadim (leak fix author), @kssenii, @alesapin.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a server-side abort triggered by passing non-UTF-8 byte sequences (for example raw
MD5(...)bytes used as a SAS token) to thedeltaLakeAzuretable function orDeltaLakeengine whenallow_experimental_delta_kernel_rs = 1. Thedelta-kernel-rsRust FFI panicked on invalid UTF-8, crossing theextern "C"boundary and aborting the server throughpanic_in_cleanup. Such inputs now returnBAD_ARGUMENTSinstead. Also fixes a memory leak of theffi::EngineBuilderallocation that could occur when builder configuration failed.Documentation entry for user-facing changes