Skip to content

panic="abort" covers only profile.release; the default CMake config links a dev-profile (unwind) staticlib #80

Closed

Description

@chriscoveries

Summary

panic = "abort" is set only for [profile.release] in the workspace
Cargo.toml, but libobs/cmake/rust.cmake calls

corrosion_import_crate(MANIFEST_PATH "${CMAKE_SOURCE_DIR}/Cargo.toml" CRATES libobs-rust CRATE_TYPES staticlib)

with no PROFILE. Per Corrosion's documented behaviour: "If you do not specify a
profile ... corrosion will select the standard dev profile if the CMake
config is either Debug or unspecified. In all other cases the release profile is
chosen for cargo."

CMAKE_BUILD_TYPE is empty unless the user passes -DCMAKE_BUILD_TYPE=..., so
the default cmake -S . -B build && cmake --build build links libobs against a
dev-profile staticlib where panic = "unwind". In that configuration a panic
in any #[unsafe(no_mangle)] pub unsafe extern "C" shim unwinds across the C
ABI, which is undefined behaviour (typically a std::thread panic hook followed
by an abort, but the unwinding itself is UB and on Windows SEH can turn it into
an unhandled exception).

Current exposure

I audited the whole merged Rust surface (rust/obs-util, rust/obs-graphics,
rust/libobs-rust) and no panic is reachable through the C ABI today, so
this is a latent hazard rather than a live crash:

  • Mutex::lock() is used poison-tolerantly everywhere
    (rust/obs-util/src/ffi/base.rs:53 unwrap_or_else(|err| err.into_inner())),
    so a poisoned handler mutex cannot panic a later call.
  • The only two panic sites in src/ are both off the C path:
    • rust/obs-util/src/base.rs:117 expect("ascii warning") — inside the safe
      core Logger, not the FFI shim (the shim uses the CRASH_HANDLER_ALREADY_SET
      CStr constant directly).
    • rust/obs-util/src/darray.rs:132 assert!(start <= self.items.len()) — in
      DArray::find; darray_find has no #[unsafe(no_mangle)] shim
      (rust/obs-util/src/ffi/darray.rs exports nothing).
  • Every shim uses .get() (not indexing) or Result-based I/O and
    wrapping_* arithmetic where C wraps, so there is no arithmetic or slice-limit
    panic. Mutex<State> in ffi/base.rs is the only shared state.

Why it matters

The guard is load-bearing for future ports, not just this one: the testing policy
and the comment in Cargo.toml both rely on "panics cannot unwind across the C
ABI". The next port that adds a single unwrap(), slice index or expect() in a
shim turns a bad argument or a full disk into UB in the default build
configuration, while every release-configuration CI run stays green — so CI
would not catch it.

Suggested fix

Pin the profile so the staticlib is always built with the abort strategy, e.g.

corrosion_import_crate(
  MANIFEST_PATH "${CMAKE_SOURCE_DIR}/Cargo.toml"
  CRATES libobs-rust
  CRATE_TYPES staticlib
  PROFILE release
)

or, if a debug-plumbing staticlib must be possible, gate a -Cpanic=abort
rustflag on the non-test profile. A one-line comment in rust.cmake recording
why the profile is pinned would keep the next person from "simplifying" it away.

Verification note

soldr cargo test --workspace --locked is green at origin/master
(75667ce45), which only exercises the dev-profile test harness and says
nothing about the staticlib.

Activity

  1. added a commit that references this issue on Oct 10, 2026
    bafe476
  2. chriscoveries commented on Oct 10, 2026

    @chriscoveries
    ContributorAuthor

    Closed as fixed: PR #81 pins PROFILE release on corrosion_import_crate (libobs/cmake/rust.cmake:14-18), so the staticlib is always built with [profile.release] panic="abort" regardless of CMAKE_BUILD_TYPE being Debug, RelWithDebInfo or unset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions