Skip to content

obs-ffmpeg: Release the settings once when a recording path is unwritable - #803

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/record-retry-crash
Oct 15, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/record-retry-crash

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Fixes #802

What and why

Start Recording no longer crashes OBS when the previous attempt failed with "Unable to write to ..." (a read-only or missing folder, a removed drive, a folder name or character the file system refuses).

  • ffmpeg_mux_start() (plugins/obs-ffmpeg/obs-ffmpeg-mux.c line 454) takes a reference to the output's settings and releases it after ffmpeg_mux_start_internal() returns. When the recording path cannot be opened, ffmpeg_mux_start_internal() calls set_file_not_readable_error() (line 314), which released the same settings again. Each failed start dropped a reference the output owns, so the output's settings were freed while it still used them, and the frontend's next Start Recording (obs_output_update() in SimpleOutput::ConfigureRecording()) wrote into freed memory.
  • The extra release dates from 9d7a6e7 (September 2022), which moved the start code into ffmpeg_mux_start_internal() and made the wrapper release the settings; the release in the error helper was left in. This change removes it (and the helper's now unused settings parameter).
  • Reported upstream by working-name in Bug: Bad character in FilenameFormatting incorrectly identified as controlled folder access problem obsproject/obs-websocket#1216 (| in the filename formatting, OBS 30.1.2) and in Error and crash when trying to create a folder with trailing spaces obsproject/obs-studio#11940 (a folder name ending in a space, OBS 31.0.1, open): the first Start Recording shows the error, the second, after clicking OK, crashes. Both on Windows; the path check is the same on every platform.

Reproduced headless (private Xvfb, private HOME, dbus-run-session, --multi): Simple and Advanced output, recording folder read-only; obs-websocket sends StartRecord, a small test module clicks OK on the error dialog as a user would, then StartRecord again:

Build Runs Second Start Recording After fixing the folder
v0.1.0-beta.20261014 AppImage 5 Simple, 2 Advanced SIGSEGV, 7 of 7 (crashed)
Stock OBS 32.2.2 2 Simple SIGSEGV, 2 of 2 (crashed)
This branch (Rust libobs lane, with the frontend) 3 Simple, 1 Advanced three attempts, each shows the error, no crash records a playable file

On a master build under gdb the crash is in get_item() <- obs_data_apply() <- obs_output_update() <- SimpleOutput::ConfigureRecording() <- SimpleOutput::StartRecording().

RED → GREEN

  • RED commit: 8e02f14 test/cmocka: Add failing test for retrying a recording on an unwritable path. test_ffmpeg_mux_unwritable_path builds obs-ffmpeg-mux.c and starts the real ffmpeg_muxer output against core video on a path whose parent is a regular file (fails for root too), with obs_data_release() wrapped (--wrap) to count releases of the output's settings. Both cases fail in both lanes: test_failed_start_releases_settings_once (released 2 times, took 1 reference) and test_retry_after_failed_start_keeps_settings (3 failed starts, each after an obs_output_update() like the frontend's, released 6 times). Needs a display (xvfb-run, like test_output_filename_reserve); skips without one (checked with env -u DISPLAY).
  • GREEN: 358693a. 2 of 2 with ENABLE_RUST_LIBOBS OFF and ON. Full ctest (private Xvfb, system libobs-opengl masked, TMPDIR unset): 237/237 in both lanes, every PipeWire/PulseAudio test ran; skipped only open_crashes_without_obs_core (two binaries). clang-format, gersemi and ci/test_registration.py clean.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): none
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not a port

Side finding, not changed here: a start that fails this way leaves the output's encoders initialized (the next start logs "Cannot apply a new video_t object after the encoder has been initialized"); #237 shuts encoders down after a start that fails later, not after start() returns false.

AI note: Claude Code (Claude Opus 5.5) wrote the code, the test, the 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 15, 2026 05:04
@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 15, 2026
rdoupe and others added 2 commits October 14, 2026 22:10
…le path

When a recording cannot be written (a folder or character the file
system refuses, a read-only or missing folder), Start Recording fails
with "Unable to write to ...", and the next Start Recording crashes
OBS. ffmpeg_mux_start() takes one reference to the output's settings
and releases it after ffmpeg_mux_start_internal() returns, but on this
failure set_file_not_readable_error() releases the same settings again.
After the first failed start the output's settings are freed while the
output still owns them, and the frontend's next obs_output_update()
writes into freed memory.

test_ffmpeg_mux_unwritable_path builds obs-ffmpeg-mux.c and starts the
real ffmpeg_muxer output against core video on a path whose parent is a
regular file, with obs_data_release() wrapped to count releases of the
output's settings. Both cases fail: one failed start releases them
twice, three failed starts six times. Needs a display (xvfb-run) and
skips without one.

Refs obs-rust#802.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…able

When ffmpeg_muxer cannot write its recording path, Start Recording
fails with "Unable to write to ...", and the next Start Recording
crashed OBS. ffmpeg_mux_start() releases the reference to the output's
settings that it takes, but set_file_not_readable_error() released it
too, so every failed start dropped a reference the output owns. The
output's settings were freed while it still used them, and the next
obs_output_update() wrote into freed memory.

The release has been in set_file_not_readable_error() since it was
written; it became an extra one when ffmpeg_mux_start() took over
releasing the settings (9d7a6e7, 2022). Remove it.

Fixes obs-rust#802.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=7ef19538370df4c7d0425adfedb1f52024190c30 secs=1634 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1792042674,"gate":"rust/all/fmt","host":"linux-x86_64","key":"063fa1a2a1fafc58e4c43a19381d11b670ad7235e2ba9ff23c4b75f661fbce50","lane":"lint","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":68,"stamp":"03846058a9ed48f16594923c162dae77","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
Ci-Attestation: {"at":1792042674,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"063fa1a2a1fafc58e4c43a19381d11b670ad7235e2ba9ff23c4b75f661fbce50","lane":"lint","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":68,"stamp":"1e67886e6062309129fafab8018665fb","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
Ci-Attestation: {"at":1792042674,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"14d13724c5ad22d6dd08f61c0cf97f7b6365c4d9817cd4e184e2e5cf87c154ba","lane":"rust-test","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":147,"stamp":"0bc06a9770f6c8707a52e5b98b1302bf","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
Ci-Attestation: {"at":1792042674,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"422166a2d51bd93b29ea4486a1be1a05ea03397a2ce59961ad95e206d00d3511","lane":"cross","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":127,"stamp":"c8b70b93ddd1a9466552dc713b758c5d","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
Ci-Attestation: {"at":1792042674,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"422166a2d51bd93b29ea4486a1be1a05ea03397a2ce59961ad95e206d00d3511","lane":"cross","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":127,"stamp":"ef0f93df5eeeba79150c908832d94397","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
Ci-Attestation: {"at":1792042674,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"422166a2d51bd93b29ea4486a1be1a05ea03397a2ce59961ad95e206d00d3511","lane":"cross","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":127,"stamp":"0d443186e49ed745eaa1411b679bfeaf","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
Ci-Attestation: {"at":1792042674,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"422166a2d51bd93b29ea4486a1be1a05ea03397a2ce59961ad95e206d00d3511","lane":"cross","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":127,"stamp":"75d7e2a574c81e59f87514edfc303602","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
Ci-Attestation: {"at":1792042674,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"422166a2d51bd93b29ea4486a1be1a05ea03397a2ce59961ad95e206d00d3511","lane":"cross","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":127,"stamp":"929d0517baeea01b8177d480886150d7","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
Ci-Attestation: {"at":1792042674,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"422166a2d51bd93b29ea4486a1be1a05ea03397a2ce59961ad95e206d00d3511","lane":"cross","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":127,"stamp":"0b76ac4924e482afcb60e45458bc1bd8","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
Ci-Attestation: {"at":1792042674,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"926b8459fac58a49cbb8222f9a40e5eb2bf9b4770b983d08de485d7cdd31ab0c","lane":"tier2-linux","parents":["4f81b2ef3a6744394a449ca7fd1f70d6b2eb0223"],"secs":1291,"stamp":"a3d81debe8d17d38ec562ef2377842df","tree":"7ef19538370df4c7d0425adfedb1f52024190c30","v":1,"via":"run"}
@zackees

zackees commented Oct 15, 2026

Copy link
Copy Markdown
Member

Rebased onto master, set ci-full (plugin change), and ran the stamped local gate. Your RED (8e02f14af) / GREEN evidence above stands.

  • Rebased on master, local gate passed; pushed as 0b3dd63.

@zackees
zackees force-pushed the fix/record-retry-crash branch from 358693a to 0b3dd63 Compare October 15, 2026 05:37
@zackees
zackees enabled auto-merge October 15, 2026 05:37
@zackees
zackees added this pull request to the merge queue Oct 15, 2026
Merged via the queue into obs-rust:master with commit b1d2ad9 Oct 15, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: obs-ffmpeg: Start Recording again after an "Unable to write to" error crashes OBS (upstream #11940)

2 participants