Skip to content

util: Zero the video fields of a formatted filename with no video - #1562

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/1509-filename-video-info
Oct 20, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/1509-filename-video-info

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #1509 (fixes the uninitialized fields; the crash before obs_startup in obs_get_video_info is a libobs core change and follows as its own PR, so the issue stays open)

What and why

os_generate_formatted_filename now formats %FPS, %CRES, %ORES and %VF as 0, 0x0, 0x0 and None when there is no video. Before, it ignored the result of obs_get_video_info, which returns false without writing the struct when no video is set up, so those specifiers were formatted from uninitialized stack memory (names like 2880154539x2880154539).

  • The C (libobs/util/platform-filename.c.h) zeroes the struct when obs_get_video_info returns false. The Rust shim (obs-util::ffi::platform_filename, ported in util: Port os_generate_formatted_filename to obs-util #1511) already started from a zeroed struct but used whatever the call left in it; it now passes zeroed fields when the call returns false, so the C and the Rust give the same name.
  • No caller in the tree reaches this: the recording outputs and the frontend format names with video up. A plugin or libobs-based tool that names a file before video is set up got a garbage name.
  • Calling it before obs_startup still crashes in obs_get_video_info, as every libobs getter does without a started core. That precondition is unchanged here; a !obs check in obs_get_video_info would be a separate libobs core change.
  • Upstream OBS has the same code in libobs/util/platform.c. Nobody has reported it there, so there is no upstream issue.
  • The Tier 3 parity test compares the Rust shim with the same C file, so both sides change together. Its header no longer lists the uninitialized fields as an intentional difference, and the rust/README.md row no longer lists the unchecked result as kept.

Changes an existing test (needs maintainer sign-off). The characterization from #262 slice 5 pinned the defect as "characterized, not endorsed". The RED commit changes the no-video case to expect the zeroed fields, since this PR fixes it:

  • test_formatted_filename's video_info_read_test: the fixture still returns false with non-zero fields (48 fps, 640x360, 320x180, NV12, standing in for what the real call leaves unset), and "%FPS %CRES %ORES %VF" now expects "0 0x0 0x0 None". Before, "%FPS %CRES" expected "48 640x360", the fields as the call left them.
  • Its Tier 1 mirror video_info_read expects "0 0x0 0x0 None" from the zeroed fields, instead of "48 640x360" from the fields as the call left them.
  • The Tier 3 parity test shim_matches_c checks the no-video case against that name on both sides (with and without spaces, and a plain name), instead of only comparing the C and the Rust as the call left them.

No other test changes.

Headless (private Xvfb, private D-Bus, fresh HOME):

Build Case Result
master 7f57efd test_formatted_filename with the RED test, libobs and libobs-with-rust, both lanes video_info_read_test fails ("48 640x360 320x180 NV12" != "0 0x0 0x0 None"), 16/17 pass
master 7f57efd obs-util platform_filename tests with the RED tests 1 of 31 fails (shim_matches_c)
This branch test_formatted_filename, libobs and libobs-with-rust, both lanes 17/17 pass
This branch full ctest, both lanes, against both libraries 335/335, none skipped
This branch obs-util platform_filename tests (Tiers 1 and 3) 31/31 pass, no exclusion for the video fields

RED → GREEN

  • RED commit: 3b90127 test: Expect zeroed video fields from a formatted filename with no video. On master, test_formatted_filename fails 1 of 17 (video_info_read_test) in the C lane (ENABLE_RUST_LIBOBS=OFF) and the libobs-with-rust lane (ON), each against both libobs and libobs-with-rust. cargo test -p obs-util --lib platform_filename: 30 passed, 1 failed.
  • GREEN: df079e3. Full ctest 335/335 in both lanes, against both libraries, none skipped (before the rebase onto 1d26efc; after it, the affected tests test_formatted_filename, test_platform* and the deque tests pass 7/7 in both lanes against both libraries); exported symbols of the two libraries identical (1766). cargo test -p obs-util: 706/706 after the rebase. cargo clippy -p obs-util --all-targets -- -D warnings: clean. uv run ci/local_gate.py --lane lint, cross, cross-release, rust-test: ok.
  • Real app: no UI or log change. The app formats names with video up, where the result is unchanged.

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
  • User-visible change: its line in docs/features.md is added (Fixed upstream bugs, Encoding, streaming and recording)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (a flag change under cmake/ or build-aux/ runs the full builds) and cross-checked with clang and MSVC (not applicable: no flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (the video-fields difference is gone from both)

The characterization of os_generate_formatted_filename (obs-rust#262 slice 5)
pinned a defect as "characterized, not endorsed": the result of
obs_get_video_info is not checked, so with no video %FPS, %CRES, %ORES
and %VF are formatted from whatever the call left in the struct. The real
obs_get_video_info returns false without writing it, so the C reads
uninitialized stack memory there; the Rust shim starts from a zeroed
struct.

This deliberately changes that characterization to expect the zeroed
fields, since the next commit makes the C and the Rust shim honour the
result:

- video_info_read_test: the fixture returns false with non-zero fields
  (48 fps, 640x360, 320x180, NV12), and "%FPS %CRES %ORES %VF" must give
  "0 0x0 0x0 None" instead of "48 640x360" from "%FPS %CRES".
- Its Tier 1 mirror video_info_read expects "0 0x0 0x0 None" from the
  zeroed fields the shim passes on with no video, instead of the fields as
  the call left them.
- The Tier 3 parity test shim_matches_c checks the no-video case against
  that name on both sides, with and without spaces and for a plain name,
  instead of comparing the two as the call left them.

On master, test_formatted_filename fails video_info_read_test, and the
obs-util platform_filename tests fail shim_matches_c (30 of 31 pass).

Refs obs-rust#1509
os_generate_formatted_filename read the video info with
obs_get_video_info and ignored the result. With no video (before a
successful obs_reset_video) that call returns false without writing the
struct, so %FPS, %CRES, %ORES and %VF were formatted from uninitialized
stack memory, giving names like 2880154539x2880154539.

Zero the struct when obs_get_video_info returns false, in the C
(libobs/util/platform-filename.c.h) and in the Rust shim
(obs-util::ffi::platform_filename), so a missing video formats as 0, 0x0
and None. The Rust shim already started from a zeroed struct, but used
whatever the call left in it.

No caller in the tree reaches this: the recording outputs and the
frontend format names with video up. A plugin or libobs-based tool that
names a file before video is set up got a garbage name. Calling it before
obs_startup still crashes in obs_get_video_info, as every libobs getter
does; that precondition is unchanged.

Upstream OBS has the same code in libobs/util/platform.c (no upstream
issue). The Tier 3 parity test compares the Rust shim with the same C
file, so both change together: its header no longer lists the
uninitialized fields as an intentional difference, and rust/README.md no
longer lists the unchecked result as kept.

Refs obs-rust#1509
@rdoupe
rdoupe requested a review from zackees as a code owner October 20, 2026 21:03
@zackees
zackees enabled auto-merge October 20, 2026 21:12
@zackees

zackees commented Oct 20, 2026

Copy link
Copy Markdown
Member

Coordinator: queued under the #1508 precedent. The only C-test change flips a case marked "characterized, not endorsed" (formatting video fields left unset when obs_get_video_info fails) to the fixed behaviour, and makes it stricter: the fixture now fills non-zero fields and the test checks %FPS %CRES %ORES %VF all format as zero/None.

@zackees
zackees added this pull request to the merge queue Oct 20, 2026
Merged via the queue into obs-rust:master with commit 856a15a Oct 20, 2026
23 checks passed
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 21, 2026
It was merged with a literal #PR placeholder. The fix landed in obs-rust#1562
(zeroed video fields) and obs-rust#1565 (no crash before obs_startup).

Refs obs-rust#1611
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 21, 2026
…ck (obs-rust#1612)

* test: Start the output interleaver with slot 0 of the video encoders empty

obs_output_set_video_encoder2() lets a multitrack video output leave
slot 0 empty and use slot 1 or higher, and obs_output_can_begin_data_
capture() accepts that (video_valid() checks every slot). The start of
the interleaver then never runs: prune_premature_packets() and
get_interleaved_start_idx() look for the first video packet of track 0
only, find none, and the start is skipped. The next packet sees both
received flags set and is sent as if started, with no offsets applied.
The packets queued before the start keep the encoder's system-time
dts_usec, so they sort after everything sent later and stay queued
until the output stops: the first keyframe is never sent, and the
output starts on a frame that is not a keyframe with timestamps that
are not offset to 0.

test_output_interleave_e2e runs its four cases again with the video
encoder in slot 1 and slot 0 empty (the output is registered
OBS_OUTPUT_MULTI_TRACK_AV so that slot 1 can be set; the slot 0 cases
are unchanged). All four fail on master against libobs and
libobs-with-rust: the first packet is audio, then video frame 1, not
the keyframe of frame 0 at dts 0. The Tier 1 port gets the same two
start cases on its model output.

Refs obs-rust#1611

* libobs: Start the output interleaver on the first video encoder's track

The interleaver's start follows the first video packet of track 0:
prune_premature_packets() and get_interleaved_start_idx() look for it,
and with slot 0 of the video encoders empty (a multitrack video output
set up with obs_output_set_video_encoder2() and an index above 0, which
obs_output_can_begin_data_capture() accepts) they never find one. The
start was then skipped, the next packet was sent as if started, without
offsets, and the packets queued before the start (the first keyframe
among them) kept their system-time dts_usec, sorted after everything
sent later, and stayed queued until the output stopped. The output
started on a frame that is not a keyframe.

Both now follow the track of the first video encoder, as
initialize_interleaved_packets() already does
(obs_output_interleave_first_video_encoder_index()). With slot 0 set,
that is track 0, so nothing changes for those outputs. The C original
and the Rust core get the same change, so the Tier 3 parity holds; the
Rust pure functions take the track as an argument (the four Tier 1
calls pass 0).

Fixes obs-rust#1611

* docs: Fill in the PR links of the obs-rust#1509 features line

It was merged with a literal #PR placeholder. The fix landed in obs-rust#1562
(zeroed video fields) and obs-rust#1565 (no crash before obs_startup).

Refs obs-rust#1611
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.

2 participants