Skip to content

Fix DeltaLake delta-kernel-rs FFI server crash and builder leak - #106109

Merged
Algunenano merged 3 commits into
ClickHouse:masterfrom
Algunenano:fix-deltalake-ffi-panic-and-builder-leak
May 30, 2026
Merged

Algunenano merged 3 commits into
ClickHouse:masterfrom
Algunenano:fix-deltalake-ffi-panic-and-builder-leak

Conversation

@Algunenano

@Algunenano Algunenano commented May 29, 2026 •

Copy link
Copy Markdown
Member

DeltaLake queries could abort the server through a Rust panic crossing the delta-kernel-rs extern "C" boundary (panic_in_cleanup). Two paths were affected:

  • set_builder_option called .unwrap() on option values that are not valid UTF-8 (for example a binary MD5(...) SAS token).
  • A panic deep inside snapshot / engine construction (for example object_store rejecting a credential that is valid UTF-8 but an invalid HTTP header value, such as a NUL byte in an S3 access key) reached panic_cannot_unwind.

The fix is in both Rust and C++, with better error handling at the FFI boundary. In the delta-kernel-rs fork, set_builder_option now returns an error instead of panicking, a new free_engine_builder lets the builder be released on the error path, and snapshot and builder_build are wrapped in catch_unwind so a panic deep in the kernel becomes an error. On the C++ side, option setting goes through KernelUtils::unwrapResult and the builder is freed with a RAII guard on the error path, which also fixes the memory leak introduced by the reverted #105897.

As an additional, not mandatory improvement, the C++ side also validates option values up front and rejects invalid UTF-8 with a clear BAD_ARGUMENTS naming the option, instead of the opaque DELTA_KERNEL_ERROR.

Closes #104509

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed a server crash when querying DeltaLake tables with allow_experimental_delta_kernel_rs enabled and a credential or option that contained invalid bytes (the Rust FFI panicked across the extern "C" boundary).

Version info

  • Merged into: 26.6.1.272
  • Backported to: 26.5.2.18, 26.4.4.21, 26.3.13.23

Algunenano and others added 2 commits May 29, 2026 13:32
Two Rust panics could cross the `extern "C"` boundary and abort the server
(issue ClickHouse#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 ClickHouse#105897.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Without this, an option value that is not valid UTF-8 (such as a binary SAS
token) surfaces as an opaque `DELTA_KERNEL_ERROR` with the raw Rust `Utf8Error`
wording. Validate the value in `setBuilderOption` and reject it with
`BAD_ARGUMENTS` naming the option. The FFI still propagates the error as defense
in depth.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2b86d27]

Summary: ✅


AI Review

Summary

This PR fixes delta-kernel-rs FFI aborts by turning invalid set_builder_option input into regular errors, guarding builder_build, snapshot, and CDF table-changes entry points with catch_unwind, and freeing failed builders from C++ with RAII. I found no remaining review findings in the current code.

Missing context / blind spots
  • ⚠️ Final CI was still in progress when reviewed. The fetched Praktika report showed no failed jobs, and the PR adds focused regressions for invalid UTF-8 credentials, guarded snapshot panics, and the CDF table_changes_from_version path.
Final Verdict

Status: ✅ Approve

No required changes.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix submodule changed At least one submodule changed in this PR. pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels May 29, 2026
@kssenii kssenii self-assigned this May 29, 2026
Comment thread contrib/delta-kernel-rs Resolved
Change Data Feed queries (`delta_lake_snapshot_start_version`) enter
`ffi::table_changes_from_version` without first building a guarded snapshot, so
the same invalid-credential panic still crossed the `extern "C"` boundary and
aborted the server. Bump the `delta-kernel-rs` fork to wrap the table-changes
FFI exports in `catch_unwind`, and add a CDF regression test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.90% 76.90% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 32/32 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@Algunenano
Algunenano enabled auto-merge May 30, 2026 11:39
@Algunenano
Algunenano added this pull request to the merge queue May 30, 2026
Merged via the queue into ClickHouse:master with commit 9d6d493 May 30, 2026
166 of 167 checks passed
@Algunenano
Algunenano deleted the fix-deltalake-ffi-panic-and-builder-leak branch May 30, 2026 12:38
robot-ch-test-poll4 added a commit that referenced this pull request May 30, 2026
Cherry pick #106109 to 26.5: Fix DeltaLake delta-kernel-rs FFI server crash and builder leak
robot-clickhouse added a commit that referenced this pull request May 30, 2026
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label May 30, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 30, 2026
Algunenano added a commit that referenced this pull request May 30, 2026
Backport #106109 to 26.5: Fix DeltaLake delta-kernel-rs FFI server crash and builder leak
robot-clickhouse-ci-1 added a commit that referenced this pull request May 30, 2026
Cherry pick #106109 to 26.3: Fix DeltaLake delta-kernel-rs FFI server crash and builder leak
robot-clickhouse added a commit that referenced this pull request May 30, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request May 30, 2026
Cherry pick #106109 to 26.4: Fix DeltaLake delta-kernel-rs FFI server crash and builder leak
robot-clickhouse added a commit that referenced this pull request May 30, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 30, 2026
Algunenano added a commit that referenced this pull request May 31, 2026
Backport #106109 to 26.4: Fix DeltaLake delta-kernel-rs FFI server crash and builder leak
Algunenano added a commit that referenced this pull request Jun 2, 2026
Backport #106109 to 26.3: Fix DeltaLake delta-kernel-rs FFI server crash and builder leak
leshikus pushed a commit to leshikus/ClickHouse that referenced this pull request Jun 8, 2026
The catch_unwind guards added in ClickHouse#106109 wrap their body in an outer `unsafe`
block, so the inner `unsafe` around `unwrap_and_parse_path_as_url` and
`log_paths` inside the closures was redundant and emitted four `unused_unsafe`
warnings on every build. Bump the delta-kernel-rs fork to drop those inner
blocks.

Closes ClickHouse#106223

Co-Authored-By: Claude Opus 4.8 <[email protected]>
SmitaRKulkarni added a commit that referenced this pull request Jun 18, 2026
…safety cherry-picks)

Cherry-pick the FFI panic-safety and builder-leak fixes from master's
delta-kernel-rs pointer onto the v0.23.0-based rebase-onto-v0.23.0 branch:

  ffi: make set_builder_option return an error instead of panicking
  ffi: add free_engine_builder to release a builder without building it
  ffi: guard snapshot and builder_build with catch_unwind
  ffi: guard table-changes (CDF) FFI exports with catch_unwind
  ffi: drop redundant inner unsafe blocks in catch_unwind closures

These correspond to the changes introduced by
#106109 and
#106381, re-applied on top of
the v0.23.0 rebase so this branch keeps the standalone snapshot FFI
functions guarded with catch_unwind.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…6109

Backport ClickHouse#106109 to 26.4: Fix DeltaLake delta-kernel-rs FFI server crash and builder leak
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…safety cherry-picks)

Cherry-pick the FFI panic-safety and builder-leak fixes from master's
delta-kernel-rs pointer onto the v0.23.0-based rebase-onto-v0.23.0 branch:

  ffi: make set_builder_option return an error instead of panicking
  ffi: add free_engine_builder to release a builder without building it
  ffi: guard snapshot and builder_build with catch_unwind
  ffi: guard table-changes (CDF) FFI exports with catch_unwind
  ffi: drop redundant inner unsafe blocks in catch_unwind closures

These correspond to the changes introduced by
ClickHouse#106109 and
ClickHouse#106381, re-applied on top of
the v0.23.0 rebase so this branch keeps the standalone snapshot FFI
functions guarded with catch_unwind.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server aborts via Rust panic_in_cleanup when delta-kernel-rs FFI panics across extern "C" boundary (STID 4793-48f3)

4 participants