Skip to content

bug: libobs/util: with ENABLE_RUST_LIBOBS=ON, config_save ignores the final close error and config_save_safe promotes the temp file #489

Closed

Description

@chriscoveries

Summary

With ENABLE_RUST_LIBOBS=ON, config_save ignores a failed final close and reports success, and config_save_safe then renames the possibly truncated temp file over the real config. The C reference checks the close result, returns CONFIG_ERROR and leaves the original file alone. Severity: medium. It needs a close failure (disk full or a network filesystem write-back error), but the result is a good config silently replaced by a truncated one.

Steps / trigger

  1. Build with ENABLE_RUST_LIBOBS=ON.
  2. Call config_save_safe(config, "tmp", "bak") (or config_save) on a filesystem where the final close of the written file fails. A test can inject EIO into close.
  3. ON returns CONFIG_SUCCESS and, for the safe variant, replaces the target with the temp file. OFF returns CONFIG_ERROR, keeps the original, and config_save_safe logs "failed to write to ".

Cause

Line numbers are against current master.

  • C reference, libobs/util/config-file.c:388-389: if (fclose(f) != 0) ret = CONFIG_ERROR; (added by libobs: Detect failed configuration flushes #70). config_save_safe then logs at :425-426 and skips the replace.
  • rust/obs-util/src/config_file.rs:881-885: write_to checks write_all and flush, but then does drop(f). Dropping a File discards the close error, and flush on a File does nothing, so it returns CONFIG_SUCCESS.
  • rust/obs-util/src/config_file.rs:901-916: save_safe sees success and renames the temp file into place. When the write fails it returns without the config_save_safe: failed to write to %s message the C version logs.

Direct config_save logs nothing on any failure in C, so the Rust version stays silent there too. Only the safe path logs.

Proposed fix

Close the file explicitly and treat a close failure as CONFIG_ERROR: take ownership of the descriptor or handle from the File and call the native close once, with no retry, in the platform layer. In save_safe, release the config mutex and log config_save_safe: failed to write to %s at error level when write_to fails, to match the C message and level. The regression test injects one close failure through an interposed close and checks the return code, that the original file and backup are untouched, that exactly one close was attempted, and the single log line on the safe path and none on the direct path.

I'd like to work on this; a fix with a regression test is ready.

Activity

  1. zackees commented on Oct 13, 2026

    @zackees
    Member

    @chriscoveries go ahead: please open the PR with the RED test commit first, then the fix (one PR per issue, targeting master). Marking it claimed for you so nobody duplicates it.

  2. added
    claimed
    on Oct 13, 2026
  3. chriscoveries commented on Oct 14, 2026

    @chriscoveries
    ContributorAuthor

    Releasing this one. We're backed up on CI and won't get it landed soon, so anyone who wants it is welcome to take it.

    If it helps, our RED test and fix are on the fork branch fix/config-save-close-error-parity. They passed review on our side but haven't been through CI, so reuse them or start fresh, whichever you prefer.

  4. zackees commented on Oct 14, 2026

    @zackees
    Member

    Claiming.

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

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions