Repository navigation
libobs, frontend: Take a NULL protocol in the output protocol lookups - #1828
Merged
Merged
Conversation
obs_is_output_protocol_registered(NULL) runs strcmp() on NULL and crashes once a service output has registered a protocol. obs_enum_output_types_with_protocol(NULL, ...) asks it first, so it crashes the same way. obs_service_get_protocol() returns NULL for a NULL service, and a service plugin can return NULL from get_protocol, so a caller can pass NULL on. obs_enum_output_protocols() with a NULL out pointer writes through it. test_output_protocol_null registers one service output with the protocol "TESTPROTO" and calls each lookup with NULL in a forked child. It expects false from obs_is_output_protocol_registered(), no callback from obs_enum_output_types_with_protocol(), and false from obs_enum_output_protocols(0, NULL). The control, registered_protocol_still_found, checks that "TESTPROTO" is still found and enumerated, and that "NOPROTO" is not. Public API only, so it also runs on the hybrid libobs; on Linux it runs under xvfb-run with -noreset. Refs obs-rust#1827
obs_is_output_protocol_registered() ran strcmp() on the protocol with no check, so a NULL protocol crashed once any service output had registered a protocol. obs_enum_output_types_with_protocol() asks it first and crashed the same way. A NULL protocol is not a registered protocol: the check now returns false, so the enumeration returns before the match and calls nothing. obs_enum_output_protocols() with a NULL out pointer returns false instead of writing through it. A registered protocol is found and enumerated as before. The auto-configuration wizard passes obs_service_get_protocol() on unchecked, first to can_use_output(), which also ran strcmp() on it. That is NULL when the wizard's service could not be created, for example without the rtmp-services plugin. can_use_output() now returns false for a NULL protocol, so the bandwidth test reaches its existing "no output" failure. GetStreamOutputType() already checked for NULL. Fixes obs-rust#1827
rdoupe
force-pushed
the
fix/output-protocol-null
branch
from
October 22, 2026 21:36
fbbcdc2 to
9f1dd90
Compare
This was referenced Oct 22, 2026
This was referenced Oct 22, 2026
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 23, 2026
) * libobs: Add Tier 1 tests for the output protocol-list match port RED for the port of libobs/obs-output-protocols.c.h to a new module, protocols, of rust/obs-output. The safe core is a stub (todo!()): count_matches(list, protocol), how many ';'-separated segments of a service output's protocol list equal the protocol, over the bytes of the two C strings before their NULs, and SEPARATOR. tests/output/protocols.rs ports test_output_protocol_list_steps 1:1: its 9 cases under the same names, in the same order, with the same assertions, the model and the exhaustive check over 131200 pairs included. The C's NULL list has no slice; it is the shim's, and the parity test checks it against the C. The "characterized, not endorsed" cases (a duplicate counts twice; the empty protocol matches the empty segments a ';' ends, not a trailing one) are kept as such. Edge cases: other separators and whitespace are segment bytes; the match at the start, middle and end of a list; one-byte segments; a protocol holding a ';' never matches; every byte value compares as itself; runs of 0 to 63 separators; a NUL inside the slice is a byte; a long protocol against a short list. Four proptests: the core equals the model over weighted bytes (high bytes, non-UTF-8, any value); appending a segment adds 1 only if it is the protocol; a segment taken from the list matches at least once and never more often than there are segments; raw bytes of every value, up to 4000, panic nowhere. The tests are a module of the existing core category binary, obs-tests-core; no new test binary. soldr cargo test -p obs-data --test obs-tests-core output::protocols fails 21 of 21 with "not yet implemented". Refs obs-rust#1829 * libobs: Port the output protocol-list match to obs-output Ports libobs/obs-output-protocols.c.h to the protocols module of rust/obs-output: how many ';'-separated segments of a service output's protocols string equal a protocol. obs_enum_output_types_with_protocol() (still C) calls its callback that many times for each service output, and the frontend picks the stream output for a protocol from it. The registered check, the output_types loop, the OBS_OUTPUT_SERVICE check and the callback stay C in obs-output.c.h; the hybrid libobs drops the C file and links the Rust shim in its place. Safe core (src/protocols.rs): count_matches() over the bytes of the two C strings before their NULs, compared as bytes, never as str: whole segments, case-sensitive, nothing trimmed. An empty list has no segment, and the segment after a trailing ';' is not scanned (the C reaches the NUL there), so the empty protocol matches only the empty segments a ';' ends. Both inputs are untrusted (output plugins, the stream service), so the module denies clippy's indexing, arithmetic, unwrap, expect, panic, todo, unimplemented and unreachable lints. Shim (src/ffi/output_protocols.rs): obs_output_protocol_list_count with the C signature reads each string to its NUL, as the C's strlen() and strchr() do, and calls the core. A NULL list counts 0, as in C. Intentional difference: a NULL protocol counts 0, where the C's strlen() crashes; libobs never passes one, because the caller returns for a NULL protocol before the match (obs-rust#1828). Kept, characterized, not endorsed (obs-rust#1831): a protocol listed twice counts twice, so the callback gets the same output twice; the empty protocol's count, which libobs never asks for. C side: the file leaves libobs.core-output for its own group, libobs.ported-output-protocols (LIBOBS_PORTED_SOURCES), whose PCH is string.h and obs-internal.h. The symbol is not EXPORT, so the shim is hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. The exported symbol sets are unchanged (1766). test_output_protocol_list_steps still compiles the C file into itself, unchanged; test_output_protocols and test_output_protocol_null see the swap through the public API. ci/test_ported_sources.py checks the group on every host. No test_output_protocol_list_steps_rust: the shim's member of libobs_rust-static also holds the rest of obs-output (the delay, the interleaver and the caption text), which needs libobs's hidden output and encoder seams and obs-util (libuuid), so the variant does not link on its own. The header of its .cmake says so; the Tier 3 parity tests compare the shim with the C instead. Refs obs-rust#1829 * libobs: Check the output protocol-list match port against the C Oracle (oracle/output_protocols.c): the original obs-output-protocols.c.h, unmodified, with obs_output_protocol_list_count renamed to oracle_obs_output_protocol_list_count. Tier 3 (tests/output/protocols_parity.rs): the shim, with C strings, and the safe core under it must give the C's count for every input: - every list of up to 7 bytes over 'A', 'B', 'a' and ';' against every protocol of up to 3 bytes over the same, the empty one included: 21845 x 85 = 1856825 pairs (the C characterization's exhaustive check has 131200), and the NULL list against each protocol; - every pair of test_output_protocol_list_steps with its expected count, its 100000-segment list (also with a trailing ';') and its 1 MiB segment; - every non-NUL byte value as a protocol against lists of it, its neighbours and separators; - a string read to its first NUL in a longer buffer, on both sides; - proptests (4000 cases each): lists built around a protocol from segments that equal it, its prefixes and extensions, case variants, empty segments, arbitrary non-NUL bytes and high bytes (not UTF-8), with leading, doubled and trailing ';', against the protocol, one byte longer, one byte shorter, lowercased and empty; and raw non-NUL bytes of every value up to 2000 with extra ';', against a segment of the list, a slice of it that may cross a ';', and random bytes. Excluded, the intentional difference: a NULL protocol, which the C's strlen() crashes on and the shim counts 0, with or without a list (checked on the Rust side). Mutation check (done once, not committed): 13 of 13 mutants fail the parity tests: a prefix match; a duplicate counted once; a case-insensitive compare; the first segment only; the segment after a trailing ';' scanned; an empty list counted as one empty segment; every trailing ';' stripped; empty segments skipped; a segment's first byte, or its last, ignored; and, in the shim, the protocol passed with its NUL, the two arguments swapped, and the list read from its second byte. The 10 core mutants also fail Tier 1. Refs obs-rust#1829 * docs: Record the output protocol-list match port The rust/README.md rows for rust/obs-output (crate table and port table), the naming.md row and the crate description now include libobs/obs-output-protocols.c.h. The port row lists what stays C, the seam, what the characterization pins and the port keeps, the intentional difference (a NULL protocol counting 0) and what Tier 2 and Tier 3 compare. Fixes obs-rust#1829
6 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1827
What and why
obs_is_output_protocol_registered(NULL)crashed OBS instrcmp(), and so didobs_enum_output_types_with_protocol(NULL, ...), which asks it first.obs_enum_output_protocols(idx, NULL)wrote through the NULL out pointer. These are spec-following fixes: a NULL protocol is not a registered protocol, so no output supports it.obs_is_output_protocol_registered()(libobs/obs.c.h) returns false for NULL.obs_enum_output_types_with_protocol()then returns before the match and calls nothing;obs-output.c.his not changed.obs_enum_output_protocols()returns false for a NULL out pointer.can_use_output()(frontend/utility/BasicOutputHandler.hpp) returns false for a NULL protocol. The auto-configuration wizard (AutoConfigTestPage.cpp.hpp220-233) passesobs_service_get_protocol()to it unchecked, and it ranstrcmp()on it before libobs was even asked. With the guard, the wizard reaches its existing "no output" failure.GetStreamOutputType(), the path that starts a real stream, already checked for NULL.A registered protocol behaves as before.
Who can hit it.
obs_service_get_protocol()returns NULL for a NULL service, and a third-party service plugin can return NULL fromget_protocol. In a normal install the UI cannot: the wizard only createsrtmp_commonandrtmp_customservices, and neither returns NULL. The wizard crashed only when it could not create its service, for example without thertmp-servicesplugin. Otherwise only a plugin or script that passes NULL reaches it. Details are in the issue.Upstream (obsproject/obs-studio master) has the same code in
libobs/obs.candfrontend/wizards/AutoConfigTestPage.cpp. I found no upstream issue for it. The line is under "Fixed upstream bugs", Stability, indocs/features.md.RED → GREEN
560eaef29test: Expect the output protocol lookups to take a NULL protocol.test_output_protocol_nullregisters one service output with the protocol"TESTPROTO"and calls each lookup with NULL in a forked child. On master's libobs it fails 3 of 4 on the C backend, the hybrid libobs and libobs-c-reference:is_registered_null,enum_types_with_protocol_nullandenum_protocols_null_outeach crash with signal 11. The control,registered_protocol_still_found, passes.9f1dd9080libobs, frontend: Take a NULL protocol in the output protocol lookups.test_output_protocol_null4/4 andtest_output_null_id7/7 against libobs with the C backend, the hybrid libobs and libobs-c-reference.OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON, both full builds with the frontend. Fullctest -j4, headless (private Xvfb with-noreset, private D-Bus, fresh HOME):HYBRID,OBS_BUILD_C_REFERENCE=ONHYBRID,OBS_BUILD_C_REFERENCE=ONOBS_LIBOBS_BACKEND=CNothing failed, was skipped or failed to run on any of the three. After rebasing onto 1751566 (#1820, #1821), the full suite was repeated on the hybrid libobs and libobs-c-reference (376/376 each). After the final rebases onto 233db44 (#1823-#1826: scene audio, effect lookups, platform file, CI), libobs and the tests were rebuilt, and the two tests, the symbol comparison,
ci/test_build_groups.pyandci/test_ported_sources.pywere repeated.uv run ci/local_gate.py --lane lintpassed.ci/test_build_groups.py,ci/test_ported_sources.py,ci/test_cmocka_includes.pyandci/test_naming.pypass.rtmp-services); the frontend change is one condition incan_use_output(), and the frontend builds on both trees.Windows/macOS: not built there. The change has no platform conditional. On Windows the test calls the lookups directly (no fork), as
test_output_null_iddoes.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)