Skip to content

oracle os_utf8_to_wcs_ptr stub returns 0 for every input and is reachable from dstr_to_wcs #84

Closed

Description

@chriscoveries

Problem

rust/obs-c-oracle/oracle/file_serializer_host.c:167-171:

size_t os_utf8_to_wcs_ptr(const char *str, size_t len, wchar_t **pstr)
{
	if (str) { ... }
	*pstr = NULL;
	return 0;
}

This stub answers "conversion succeeded" with 0 for every input, which is
both a wrong return value and a wrong *pstr.

It is not dead code. libobs/util/dstr.c:727 dstr_to_wcs calls
os_utf8_to_wcs_ptr, and rust/obs-c-oracle/build.rs:35 compiles
dstr.c into the same oracle, so oracle_dstr_to_wcs links against this stub.
The reason it has not caused a failure yet is only that no test declares or
calls oracle_dstr_to_wcs today.

Why it matters

This is the same failure mode that produced #79, and it is the more dangerous
of the two. In #79 the os_fopen stub was stricter than libobs, so the
differential test silently certified a fiction and a port author imported that
fiction into file_serializer.rs with a comment asserting it as libobs
behaviour. Here, the first port that pulls in a dstr-dependent source path and
runs it through the oracle will see os_utf8_to_wcs_ptr always fail, will
conclude "C's conversion fails", and will encode a refusal into the port — again
matching the stub rather than libobs/util/platform.c:445-456.

Note the two directions of failure differ: for os_fopen the stub made the
oracle stricter than libobs; for os_utf8_to_wcs_ptr the stub makes every
conversion fail, including ones libobs performs successfully.

Suggested fix

Mirror libobs/util/platform.c:445-456 faithfully:

size_t os_utf8_to_wcs_ptr(const char *str, size_t len, wchar_t **pstr)
{
	if (str) {
		size_t out_len = os_utf8_to_wcs(str, len, NULL, 0);
		*pstr = bmalloc((out_len + 1) * sizeof(wchar_t));
		return os_utf8_to_wcs(str, len, *pstr, out_len + 1);
	} else {
		*pstr = NULL;
		return 0;
	}
}

with os_utf8_to_wcs delegating to a MultiByteToWideChar(CP_UTF8, 0, …)-based
utf8_to_wchar on Windows, as now done for os_fopen in #82.

Suggested follow-up hardening

Add a #[test] in the oracle crate (or an assertion in a dstr port's Tier 1)
that pins oracle_dstr_to_wcs against a known string on Windows, so a future
stub regression cannot pass silently. That is cheap and closes exactly this
class of "oracle lies, test agrees, port is wrong".

Related: #79 (fixed by #82), #80 (fixed by #81).

Activity

  1. b7216309-jpg commented on Oct 10, 2026

    @b7216309-jpg
    Contributor

    I'm taking this one, with a PR shortly. The plan: compile the real util/utf8.c into the oracle and copy the platform.c conversions verbatim. That also fixes the other two zero stubs next to it, os_mbs_to_utf8_ptr and wchar_to_utf8. Add a test that pins dstr_to_wcs (and dstr_from_wcs/dstr_from_mbs) against known strings.

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