Skip to content

libobs, frontend: Don't crash on a NULL output id in Settings - #219

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/217-output-null-id
Oct 11, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/217-output-null-id

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Description

Opening Settings crashed OBS when no registered output supports the stream protocol (for example when no output plugin is loaded, or the stream service uses a protocol no output handles). With this change Settings opens normally in that case, and the id-keyed output getters in libobs return their not-found value for a NULL id instead of crashing.

The cause: OBSBasicSettings::ServiceAndVCodecCompatible(), ServiceAndACodecCompatible() and ResetEncoders() declare const char *output; without initialising it (frontend/settings/OBSBasicSettings_Stream.cpp:1545, :1580, :1749, :1757) and fill it from obs_enum_output_types_with_protocol(). When no output matches, the callback never runs and the pointer stays uninitialised (NULL in practice), and it is passed to obs_get_output_supported_video_codecs() / obs_get_output_supported_audio_codecs(). Those call find_output() (libobs/obs-output.c:122), which runs strcmp() on the id (obs-output.c:126) and crashes. That matches the report's backtrace (find_output (id=0x0) from ResetEncoders).

  1. test: Pin output getters crashing on a NULL id: test_output_null_id registers one output type, then calls each id-keyed getter (obs_get_output_supported_video_codecs, obs_get_output_supported_audio_codecs, obs_get_output_flags, obs_output_get_display_name, obs_output_defaults, obs_get_output_properties) with NULL, each in a forked child, and expects the not-found value. 6 of 7 fail on this commit (the child crashes with signal 11). The control, registered_output_still_found, passes. It needs a display for obs_startup and skips without one, like test_audio_io.
  2. libobs, frontend: Don't crash on a NULL output id in Settings: find_output() treats a NULL id as not found, and the four frontend output pointers are initialised to nullptr. The frontend already handles a NULL codec list by not filtering the encoders. All 7 tests pass.

Motivation and Context

Fixes #217 (upstream obsproject/obs-studio#12843, reported by HanabishiRecca)

Why this one: it's a crash on opening Settings, so a user in this state can't get into Settings to fix the setup that caused it. The reporter already found the cause, the fix is small, and there is no upstream fix. It also stops reading an uninitialised pointer, which is undefined behaviour whatever its value.

How Has This Been Tested?

Automated: test_output_null_id fails 6 of 7 at the RED commit and passes 7 of 7 at the GREEN commit, after clean rebuilds, under a private Xvfb. clang-format and gersemi are clean.

By hand, headless: I ran the full frontend under a private X server with a profile crafted so that no registered output supports its stream protocol. Before the fix, opening Settings crashed with the reporter's exact stack (strcmp in find_output (id=0x0) from OBSBasicSettings::ResetEncoders). After the fix, Settings opens.

Not tested:

  • The reporter's exact setup (no outputs in the system at all); the crafted profile reaches the same code path.
  • Windows and macOS.
  • The Rust and Docker lanes of the local gate.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner October 11, 2026 07:48
@zackees
zackees force-pushed the fix/217-output-null-id branch from 12a3c6f to 21c02f2 Compare October 11, 2026 08:02
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped. test_output_null_id skips without a display, so I ran it under xvfb-run on each commit's Tier 2 build:

  • RED (3bcfa214a): 1 of 7 passed with ENABLE_RUST_LIBOBS OFF and 1 of 7 with it ON. The 6 NULL-id getters failed.
  • GREEN (12a3c6f25): 7 of 7 passed OFF and 7 of 7 passed ON. Plain Tier 2 passed 71 of 71 OFF and 71 of 71 ON, and the local gate passed.

As with #207, CI has no display, so this test only guards anything where Xvfb is available. Merging once CI is green.

@rdoupe

rdoupe commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator Author

Same macOS cause as described in #218 (the new obs-studio-rust tag breaks version parsing on macOS); not from this change.

rdoupe and others added 2 commits October 11, 2026 01:30
obs_get_output_supported_video_codecs(NULL) and the other id-keyed
output getters reach find_output(), which runs strcmp() on the id. The
Settings window passes NULL there when no registered output supports
the stream protocol, which crashes OBS (obsproject/obs-studio#12843,
reported by HanabishiRecca).

The test registers one output type, then calls each getter with NULL in
a forked child and expects the not-found value instead of a crash.

Refs obs-rust#217.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
When no registered output supports the stream protocol,
obs_enum_output_types_with_protocol() never calls back, and the Settings
window passed its uninitialized `output` pointer (in practice NULL) to
obs_get_output_supported_video/audio_codecs(). find_output() then ran
strcmp() on it and OBS crashed while opening Settings
(obsproject/obs-studio#12843, reported by HanabishiRecca).

Initialize the frontend's output id to nullptr, and make find_output()
treat a NULL id as not found so every id-keyed output getter returns its
not-found value instead of crashing. The frontend already handles a NULL
codec list by not filtering encoders.

Fixes obs-rust#217.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=bfd01413d2e2181540fe7c1d543605f8fcf4b94e secs=139 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791707559,"gate":"rust/all/fmt","host":"linux-x86_64","key":"f487ee6ddd2034f123e07ec0be5332e6c7110ac789e9d66d148c12a346bf7808","lane":"lint","parents":["0a800516cdf38a05cba21de15c942c436c40d0e5"],"secs":53,"stamp":"e994bdf6dbb1567af2f64d6c4079e2f5","tree":"bfd01413d2e2181540fe7c1d543605f8fcf4b94e","v":1,"via":"run"}
Ci-Attestation: {"at":1791707559,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"f487ee6ddd2034f123e07ec0be5332e6c7110ac789e9d66d148c12a346bf7808","lane":"lint","parents":["0a800516cdf38a05cba21de15c942c436c40d0e5"],"secs":53,"stamp":"160692bcdd3ad07573f6fde4c3b8491c","tree":"bfd01413d2e2181540fe7c1d543605f8fcf4b94e","v":1,"via":"run"}
Ci-Attestation: {"at":1791707559,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"bb313a18e33e93c590f3d3d37b54eb0c722b9a7db3be29b908c54ff5c8477ea8","lane":"rust-test","parents":["0a800516cdf38a05cba21de15c942c436c40d0e5"],"secs":33,"stamp":"80dc336476ed8ac953c0273373445133","tree":"bfd01413d2e2181540fe7c1d543605f8fcf4b94e","v":1,"via":"run"}
Ci-Attestation: {"at":1791707559,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"6232872e9547a08b8ba4ec77a9f3ecb04cc0fa21633c9197d34edfcee2aa51f7","lane":"tier2-linux","parents":["0a800516cdf38a05cba21de15c942c436c40d0e5"],"secs":53,"stamp":"d5b27c3d34bdd3aa1902e1cc7e1ffea0","tree":"bfd01413d2e2181540fe7c1d543605f8fcf4b94e","v":1,"via":"run"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs/frontend: Settings crashes on a NULL output id when the stream protocol has no output (upstream #12843)

2 participants