Skip to content

Oracle os_fopen stub is stricter than libobs on Windows; the divergence already leaked into the file-serializer port #79

Closed

Description

@chriscoveries

Root cause

The Tier 3 oracle's Windows path stub is stricter than libobs.
rust/obs-c-oracle/oracle/file_serializer_host.c:31-59:

static wchar_t *utf8_to_wide(const char *path)
{
    ...
    n = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path, -1, NULL, 0);  /* :38 */
    if (n <= 0)
        return NULL;

so the oracle's os_fopen fails for any path that is not valid UTF-8.

libobs does not. os_fopen (libobs/util/platform.c:55-71) calls
os_utf8_to_wcs_ptr (platform.c:445-456) and discards its return value;
the conversion ends at utf8_to_wchar (libobs/util/utf8.c:47), which calls

ret = MultiByteToWideChar(CP_UTF8, 0, in, i_insize, out, (int)outsize);

dwFlags = 0, no MB_ERR_INVALID_CHARS. On Vista and later that substitutes
U+FFFD for invalid sequences and returns > 0. So a non-UTF-8 path is attempted,
never rejected; the only observable outcome is that the mangled path normally
does not exist, os_fopen returns NULL, and the caller sees the usual failure.

Impact

Tier 3 differential parity on Windows compares the Rust shims against a stub
that is stricter than production libobs, so it can certify port behaviour that
differs from the real library. It already has, twice:

  1. rust/obs-util/src/file_serializer.rs:47-52 returns None from
    path_from_bytes without attempting the open when the path is not valid
    UTF-8, justified by the comment at :49 ("os_fopen rejects a path that is
    not valid UTF-8"), which is false. This makes file_input_serializer_init,
    file_output_serializer_init and file_output_serializer_init_safe all
    return false where libobs would attempt the U+FFFD-substituted path. Note
    the behaviour matches the oracle stub, not libobs/util/platform.c.

  2. The same false premise produced the "C's UTF-8→UTF-16 conversion fails the
    open" note recorded in PR rust: Port util/config-file.c to obs-util #77, now at
    rust/obs-util/tests/config_file_parity.rs:20-23. The config-file port's
    path_from_bytes (rust/obs-util/src/config_file.rs:764-770, unmerged)
    does substitute U+FFFD, so these two ports take opposite approaches to the
    identical conversion.

The existing coverage does not catch it: non_utf8_filename_matches_oracle is
#[cfg(unix)] (rust/obs-util/tests/file_serializer_parity.rs:754), so it
never runs on the Windows CI lane where the stub differs.

Reproducer

Windows only. In file_serializer_parity.rs add an un-#[cfg(unix)]-gated
case that creates a file named with the U+FFFD-substituted form of a non-UTF-8
path (e.g. "scratch\\\u{FFFD}.ini"), then calls both
oracle_file_input_serializer_init and file_input_serializer_init with
b"/tmp/\xff\xfe.ini"-style bytes. Expected: both open it. Actual with the
current stub: the oracle returns false immediately, and the Rust shim also
returns false, so they agree — and are both wrong about production libobs.

Suggested fix

  1. Remove MB_ERR_INVALID_CHARS from utf8_to_wide()
    (rust/obs-c-oracle/oracle/file_serializer_host.c:38,44) so the oracle
    matches utf8_to_wchar's flags-0, U+FFFD-substituting behaviour. Remove the
    #[cfg(unix)] gate on the non-UTF-8 test so it runs on Windows; a
    rust/obs-c-oracle-only change cannot be validated on this host.
  2. Then fix the port to match: rust/obs-util/src/file_serializer.rs:47-52
    should substitute U+FFFD like the config-file port, with the comment
    corrected — or the refusal should be recorded as an intentional difference in
    the test file and the tracking issue as the testing policy requires. Either
    way the two ports should agree.
  3. Separately, os_utf8_to_wcs_ptr at
    rust/obs-c-oracle/oracle/file_serializer_host.c:167-171 returns NULL/0 for
    every input, which is also unfaithful. Nothing in the current oracle TU set
    calls it, but it will silently mislead the next port that pulls in a
    dstr-dependent source.

The whole correctness argument for these ports is "the differential test proved
the Rust matches C". With this stub, on Windows, that argument is false for path
handling.

Activity

  1. chriscoveries commented on Oct 10, 2026

    @chriscoveries
    ContributorAuthor

    Closed as fixed: PR #82 makes the oracle's UTF-8 -> UTF-16 conversion match libobs (flags 0, U+FFFD substitution) instead of failing on invalid UTF-8.

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