Skip to content

bug: obs-util: CONFIG_OPEN_ALWAYS truncates unreadable configs #1942

Closed

Description

@ProtonDev-sys

Location

rust/obs-util/src/config_file.rs:501-523, read_file / parse_file_into:

let data = std::fs::read(path).ok()?;
...
None if always_open => match std::fs::File::create(&path) {
    Ok(_) => None,
    Err(_) => return CONFIG_FILENOTFOUND,
}

The C reference at libobs/util/config-file.c.h:230-254 opens rb, retries w+ only if the open failed, and reports success with an empty config if a subsequent read produces no data.

Class

Data loss / C compatibility regression in the Rust port.

How it is reached

An unprivileged local user opens their existing write-only mode 0200 config with CONFIG_OPEN_ALWAYS. Rust cannot read it, then File::create opens write-only and truncates the existing bytes. The C w+ fallback requires both read and write access, fails, and preserves the file with CONFIG_FILENOTFOUND.

Rust also merges open failures with failures after a successful open. Such read failures must not enter a destructive create fallback. For example, opening a directory for reading succeeds on Linux, while reading it fails; C returns success with an empty config for either open mode and for defaults.

Only the local user's own file permissions and configuration are involved; no credential disclosure or remote input is needed. This is a normal public bug under SECURITY.md.

Duplicate search: open PRs for config; all issues for config-file, config truncate, and config write-only. No matching issue or PR found.

Proposed fix and failing test

Separate opening from reading. Match the C fallback's w+ read/write/create/truncate access, and only use it after the initial open fails. Keep the C behavior of an empty successful parse after a read error.

Add safe-core and C-oracle differential regressions in the existing utilities category harness. On an unprivileged Linux user, create separate configs with known bytes, chmod to 0200, call CONFIG_OPEN_ALWAYS, restore permissions, and assert both return values and byte preservation. Cover read failure after successful open with a directory and both open modes/defaults. Keep existing C tests and public headers unchanged.

Activity

  1. ProtonDev-sys commented on Oct 23, 2026

    @ProtonDev-sys
    ContributorAuthor

    Claiming: config-file open/read failure compatibility.

    1. Reproduce mode-0200 config data loss as the unprivileged dev user on the other PC, and distinguish successful opens followed by failed reads.
    2. Commit RED safe-core and C-oracle regressions in the existing utilities harness and immediately open a draft PR against master.
    3. Apply the minimal Rust fix, run relevant tests plus fmt/clippy on that PC, and mark the PR ready with exact evidence.

    First draft PR expected within this session, about 20 minutes. Existing C tests/public headers and the C++ obs-websocket plugin stay unchanged.

  2. added
    claimed
    on Oct 23, 2026
  3. ProtonDev-sys commented on Oct 23, 2026

    @ProtonDev-sys
    ContributorAuthor

    Reproduced and fixed in #1944.

    RED 8d4118d: 68 passed / 4 failed as unprivileged dev (uid 1000) on DESKTOP-3FLAOFG Ubuntu/WSL. Mode-0200 CONFIG_OPEN_ALWAYS: C returned -1 with all 18 original bytes; Rust returned 0 with zero bytes. Separate successful-open/read-error directory regressions also failed.

    GREEN f46617c: full obs-util suite 832/832 plus 2 doctests passed; fmt and clippy (-D warnings) passed. Production change is 19 added / 22 removed lines (net -3). Existing C tests/public headers are unchanged, no intentional C difference, and Tier 2 remains with PR CI because Docker is unavailable locally. Both read-error defaults and open modes are covered.

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