Repository navigation
libobs: Refuse an output size that the alignment makes invalid - #1734
Merged
zackees merged 2 commits intoOct 22, 2026
Merged
Conversation
…to 0 An output width of 2 or 3 passes the 2..32768 size check of obs_reset_video(), and the output alignment to a multiple of 4 then makes it 0. The reset has freed the old video by then, so it fails with no video left, and obs_get_video() then crashes on the missing main mix. obs-rust#1714 pinned this as characterized, not endorsed. test_video_output_plan now expects the new obs_video_output_size_valid() to refuse the widths 2 and 3 (any height) and to agree with obs_video_size_valid() for every other size, including the sizes just above the maximum. The alignment assertions are unchanged. test_video_output_formats gets a real-libobs case: a reset to a valid size, then to an output width of 2 or 3, which must return OBS_VIDEO_INVALID_PARAM and leave the old video running, then a later reset to a valid size, which must work. Refs obs-rust#1713
obs_reset_video() checked the output size (2..32768) before aligning the width down to a multiple of 4 and the height to a multiple of 2. An output width of 2 or 3 passed the check and was aligned to 0. By then the reset had freed the old video, so video_output_open() failed with no video left, and obs_get_video() then crashed on the missing main mix. The output size is now checked as given and once aligned, by the new hidden obs_video_output_size_valid() in obs-video-plan.c.h, before anything is freed. A width of 2 or 3 now returns OBS_VIDEO_INVALID_PARAM and the old video keeps running. Every other size is accepted or refused exactly as before: heights of 2 and 3 align to 2 and stay valid, and the alignment only lowers a size, so no size above the maximum becomes valid. The base size is not aligned and keeps its check. The Settings dialog (minimum 32) and obs-websocket SetVideoSettings (minimum 8) never send such a width; plugins and scripts can. obs_init_video() also checked pthread_mutex_init() for its three mutexes with < 0. pthread returns a positive error number, so a failure was never caught; it checks != 0 now, like the rest of obs.c.h. Refs obs-rust#1713
rdoupe
force-pushed
the
fix/video-output-size-validation
branch
from
October 22, 2026 06:07
2c4d545 to
9f87669
Compare
zackees
enabled auto-merge
October 22, 2026 06:12
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 22, 2026
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 22, 2026
…them The Windows cmocka does not export cm_print_error(), which fail_msg() expands to there, so a Windows-built test that calls it stops the Windows Tier 2 build with LNK2019 before CTest runs. obs-rust#1741 converted three of the four calls in test_video_output_plan; the one in output_size_check_edges (added by obs-rust#1734) is still there, so the Windows link still fails. The same pattern as obs-rust#1591 for obs-rust#1580: it is now fprintf(stderr, ...) with the same format and arguments, a terminating newline, and then a plain fail(), under the same condition. test_settings_track_rows (Qt6::Widgets only, so Windows builds it too) had three such calls. It links on Windows today, but it is the only other Windows-built test that calls fail_msg(), and the new check holds every such test to the same rule, so it gets the same change. No condition, loop, case or assertion changes. Refs obs-rust#1713
This was referenced Oct 22, 2026
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 22, 2026
…them The Windows cmocka does not export cm_print_error(), which fail_msg() expands to there, so a Windows-built test that calls it stops the Windows Tier 2 build with LNK2019 before CTest runs. obs-rust#1741 converted three of the four calls in test_video_output_plan; the one in output_size_check_edges (added by obs-rust#1734) is still there, so the Windows link still fails. The same pattern as obs-rust#1591 for obs-rust#1580: it is now fprintf(stderr, ...) with the same format and arguments, a terminating newline, and then a plain fail(), under the same condition. test_settings_track_rows (Qt6::Widgets only, so Windows builds it too) had three such calls. It links on Windows today, but it is the only other Windows-built test that calls fail_msg(), and the new check holds every such test to the same rule, so it gets the same change. Once it links, test_video_output_plan fails on Windows in techniques_exist_in_the_effect ("technique Planar_Y is not in format_conversion.effect"): the Windows checkout gives the effect file CRLF line endings, and the "\ntechnique NAME\n" needles never match "\r\n". The test now drops the CRs from the text it read before searching. Converting the effect to CRLF reproduces the failure on Linux, and the test passes with that file after the change. No condition, loop, case or assertion changes. Refs obs-rust#1713
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 22, 2026
…them The Windows cmocka does not export cm_print_error(), which fail_msg() expands to there, so a Windows-built test that calls it stops the Windows Tier 2 build with LNK2019 before CTest runs. obs-rust#1741 converted three of the four calls in test_video_output_plan; the one in output_size_check_edges (added by obs-rust#1734) is still there, so the Windows link still fails. The same pattern as obs-rust#1591 for obs-rust#1580: it is now fprintf(stderr, ...) with the same format and arguments, a terminating newline, and then a plain fail(), under the same condition. test_settings_track_rows (Qt6::Widgets only, so Windows builds it too) had three such calls. It links on Windows today, but it is the only other Windows-built test that calls fail_msg(), and the new check holds every such test to the same rule, so it gets the same change. Once it links, test_video_output_plan fails on Windows in techniques_exist_in_the_effect ("technique Planar_Y is not in format_conversion.effect"): the Windows checkout gives the effect file CRLF line endings, and the "\ntechnique NAME\n" needles never match "\r\n". The test now drops the CRs from the text it read before searching. Converting the effect to CRLF reproduces the failure on Linux, and the test passes with that file after the change. No condition, loop, case or assertion changes. Refs obs-rust#1713
5 of 7 tasks
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 22, 2026
Ports libobs/obs-video-plan.c.h to the video_plan module of a new crate, rust/obs-core, for the units extracted from libobs/obs.c.h. The plan tells obs_reset_video() which sizes it takes and how it aligns the output, and tells the mix setup, per output format, the GPU conversion (the techniques of format_conversion.effect and their texel sizes), the size and format of each conversion plane, and the render texture format and color space. obs.c.h (still C) creates the textures and surfaces from it; the hybrid libobs drops the C file and links the Rust shims. Safe core (src/video_plan.rs): size_valid() with OBS_SIZE_MIN and OBS_SIZE_MAX, align_output_size(), output_size_valid() (valid as given and after the alignment, obs-rust#1734), scale_type_name(), and output_plan() with the C's three steps: the techniques and texel sizes, the planes, and the render textures. Technique names are 'static c"..." strings. The texel sizes are 1.0 / size as f32, the C's 1.f / (float)size bit for bit (infinite for a zero size, as in C). The sizes come from profiles, obs-websocket SetVideoSettings and scripts, so the module denies clippy's indexing_slicing, arithmetic_side_effects, unwrap_used, expect_used, panic, todo, unimplemented and unreachable; nothing panics for any input. Shim (src/ffi/video_plan.rs): the five functions with the C signatures, and #[repr(C)] struct obs_video_plane and struct obs_video_output_plan, returned by value. The enums cross as c_ints; a value outside its enum takes the C's default: branch. Intentional difference: a null pointer to obs_video_align_output_size is skipped (C dereferences it); the other pointer is still aligned. C side: the file leaves libobs.core for its own group, libobs.ported-video-plan (LIBOBS_PORTED_SOURCES), whose PCH is obs-internal.h, so the C reference and the C backend keep compiling it. The functions are declared in obs-internal.h without EXPORT, so the shims are hidden: rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt. libobs-rust depends on obs-core and re-exports its ffi. Results: test_video_output_plan (10 of 10) and test_video_output_formats (4 of 4, under a private Xvfb) pass against the C-backend libobs, the hybrid libobs and libobs-c-reference. The exported symbol sets are identical, 1766 in each. Tier 1: obs_core:: 18 of 18. Refs obs-rust#1713
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 22, 2026
* libobs: Add Tier 1 tests for the video output plan port RED for the port of libobs/obs-video-plan.c.h to a new crate, rust/obs-core, module video_plan: the crate for the units extracted from libobs/obs.c.h, as the claim on obs-rust#1713 proposed. The safe core is a stub (todo!()): size_valid(), align_output_size(), output_size_valid(), scale_type_name() and output_plan(). The C enums it takes or returns, gs_color_format, gs_color_space and obs_scale_type, are plain data in header order (GsColorFormat, GsColorSpace, ObsScaleType); video_format and video_colorspace are obs-media-io's. A value outside its enum is None, the C's default: branch. tests/obs_core/video_plan.rs ports test_video_output_plan 1:1: its 10 cases under the same names, in the same order, with the same inputs and the same expected values, including the written-out plan per format and the bit-for-bit float comparison over every format x colorspace x size. techniques_exist_in_the_effect reads libobs/data/format_conversion.effect from the source tree, with CR removed as the C test does. Edge cases: the enum tables in header order, the size bounds, a zero size (infinite texel size, as 1.f / (float)0), u32::MAX sizes, technique names as C identifiers, techniques and planes in pairs, and two proptests over any u32 sizes: the plan against the written-out rules, and the alignment and the output size check. The tests are a module of the existing core category binary, obs-tests-core; no new test binary (8 of 8). soldr cargo test -p obs-data --test obs-tests-core obs_core:: fails 17 of 18 with "not yet implemented"; only enum_tables_in_header_order passes. Refs obs-rust#1713 * libobs: Port the video output plan to obs-core Ports libobs/obs-video-plan.c.h to the video_plan module of a new crate, rust/obs-core, for the units extracted from libobs/obs.c.h. The plan tells obs_reset_video() which sizes it takes and how it aligns the output, and tells the mix setup, per output format, the GPU conversion (the techniques of format_conversion.effect and their texel sizes), the size and format of each conversion plane, and the render texture format and color space. obs.c.h (still C) creates the textures and surfaces from it; the hybrid libobs drops the C file and links the Rust shims. Safe core (src/video_plan.rs): size_valid() with OBS_SIZE_MIN and OBS_SIZE_MAX, align_output_size(), output_size_valid() (valid as given and after the alignment, obs-rust#1734), scale_type_name(), and output_plan() with the C's three steps: the techniques and texel sizes, the planes, and the render textures. Technique names are 'static c"..." strings. The texel sizes are 1.0 / size as f32, the C's 1.f / (float)size bit for bit (infinite for a zero size, as in C). The sizes come from profiles, obs-websocket SetVideoSettings and scripts, so the module denies clippy's indexing_slicing, arithmetic_side_effects, unwrap_used, expect_used, panic, todo, unimplemented and unreachable; nothing panics for any input. Shim (src/ffi/video_plan.rs): the five functions with the C signatures, and #[repr(C)] struct obs_video_plane and struct obs_video_output_plan, returned by value. The enums cross as c_ints; a value outside its enum takes the C's default: branch. Intentional difference: a null pointer to obs_video_align_output_size is skipped (C dereferences it); the other pointer is still aligned. C side: the file leaves libobs.core for its own group, libobs.ported-video-plan (LIBOBS_PORTED_SOURCES), whose PCH is obs-internal.h, so the C reference and the C backend keep compiling it. The functions are declared in obs-internal.h without EXPORT, so the shims are hidden: rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt. libobs-rust depends on obs-core and re-exports its ffi. Results: test_video_output_plan (10 of 10) and test_video_output_formats (4 of 4, under a private Xvfb) pass against the C-backend libobs, the hybrid libobs and libobs-c-reference. The exported symbol sets are identical, 1766 in each. Tier 1: obs_core:: 18 of 18. Refs obs-rust#1713 * obs-c-oracle: Compare the video output plan port with the original C The oracle, oracle/video_plan.c, is libobs/obs-video-plan.c.h, unmodified, with its five functions renamed to oracle_*. The rename also renames the struct tag obs_video_output_plan, in obs-internal.h and the file alike, which leaves the layout as it is. It also reports the layout of struct obs_video_plane and struct obs_video_output_plan, the width of the enums, and the gs_color_format, gs_color_space, obs_scale_type, video_format and video_colorspace values. Tier 3 (tests/obs_core/video_plan_parity.rs), in obs-tests-core: - the layout and the enum values against the C header; - exhaustively, every video_format and video_colorspace value, with -1, one and two past the end, INT_MIN and INT_MAX, at 24 sizes (the characterization's, 0, 32769, 65536, 2^31 - 1, 2^31, 2^32 - 2 and 2^32 - 1) for each of width and height: 31 x 11 x 24 x 24 plans, every field, technique names byte for byte, floats bit for bit; - every obs_scale_type value and values outside it; - the size checks and the alignment at those sizes; - proptests (4096 cases each) over any format and color space value and any u32 sizes, sizes up to 65536, and the size checks over any u32 and near the bounds. Excluded, the one intentional difference: a null pointer to obs_video_align_output_size, which the shim skips and C dereferences; a shim-only test pins it. 11 of 11 pass. Deliberate breaks, not committed, each caught: the P216 chroma plane at half height (3 tests fail), the output size not checked again after the alignment (the edge sweep fails), the PQ and HLG technique sets of P416 swapped (3), and the texel size from a different rounding (3). Refs obs-rust#1713 * docs: Add the obs-core rows for the video output plan port naming.md: libobs/obs.c.h and the units extracted from it (obs-video-plan.c.h so far) go in rust/obs-core. rust/README.md: the obs-core layout row and the obs-video-plan.c.h row of the ported table, with its one intentional difference. testing-policy.md: obs-core's tests are a module of the core category binary, obs-tests-core. Refs obs-rust#1713
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.
Refs #1713 (PR 2 of the plan: the C fix of bugs 4 and 6, which #1714 found while extracting the video output plan. The port, step 3, follows and closes the issue.)
What and why
Two fixes in
libobs/obs.c.handlibobs/obs-video-plan.c.h, described on #1713. This is C only, and the port copies the fixed C. It lands before the port, so the port starts from the fixed behaviour and the tests that pin it.obs_reset_video()checked the output size (2..32768) and then, inobs_reset_video_internal(), aligned the width down to a multiple of 4 and the height to a multiple of 2. A width of 2 or 3 passed the check and was aligned to 0. By then the reset had already freed the old video, sovideo_output_open()failed with no video left:obs_reset_video()returnedOBS_VIDEO_FAIL,obs_get_video_info()returned false, andobs_get_video()then crashed on the missing main mix (SIGSEGV inobs_get_video(), seen on master with a small driver against the real libobs). The output size is now checked as given and once aligned, by a new hiddenobs_video_output_size_valid()inobs-video-plan.c.h, before anything is freed. A width of 2 or 3 now returnsOBS_VIDEO_INVALID_PARAM(already a documented return value ofobs_reset_video()), and the old video keeps running.test_video_output_planchecks the new function againstobs_video_size_valid()over 17 x 17 edge sizes: only the widths 2 and 3 differ.obs_reset_video()themselves. The Settings dialog has a minimum of 32, and obs-websocketSetVideoSettingsrequires at least 8.obs_init_video()checkedpthread_mutex_init()fortask_mutex,encoder_group_mutexandmixes_mutexwith< 0. pthread returns a positive error number, so a failure was never caught. It checks!= 0now, like the rest ofobs.c.h. There is no test:pthread_mutex_init()with default attributes does not fail on our platforms.obs_video_output_size_validis local. A caller that passed an output width of 2 or 3 now getsOBS_VIDEO_INVALID_PARAMinstead ofOBS_VIDEO_FAILand keeps its video. As before, a refused reset does not touch the caller'sobs_video_info(before, the failing reset left its width aligned to 0).libobs/obs.c:size_valid()withOBS_SIZE_MIN 2runs beforestop_video()/obs_free_video(), andobs_reset_video_internal()then applies the0xFFFFFFFCmask; the threepthread_mutex_init(...) < 0checks are there too. I found no user report (searched the obs-studio and obs-websocket trackers forobs_reset_videocrashes, small or 2-pixel output resolutions andSetVideoSettingscrashes).Follow-ups, not in this PR.
obs_canvas_create()andobs_canvas_reset_video()(obs-canvas.c.h) check neither the base nor the output size and do not align it, so they cannot hit bug 4 (a width of 2 stays 2 there), but they accept sizes thatobs_reset_video()refuses (0, 1, above 32768). Adding the check is not this one-line fix:obs_canvas_reset_video_internal()clears the canvas mix before it creates the new one,obs_canvas_create()returns a canvas without a mix when the mix fails, nothing characterizes canvas sizes today, and refusing sizes there changes what the canvas API accepts. It wants its own characterization test, then a fix.obs_context_data_init()checkspthread_mutex_init(&context->rename_cache_mutex, NULL) < 0(not the video init path; upstream has it too). Same one-character class as bug 6, left for its own change.This deliberately changes an existing test (needs maintainer sign-off). The RED commit changes only the bug-4 assertions that #1714 pinned as "characterized, not endorsed", and adds one real-libobs case. It changes no other case:
test/cmocka/test_video_output_plan.c: the header paragraph "Characterized, not endorsed: obs_video_size_valid() accepts an output width of 2 or 3, and obs_video_align_output_size() then masks it to 0, ..." now says that the output size is also checked after the alignment and thatobs_reset_video()refuses those widths. The casewidth_2_and_3_align_to_0becomeswidth_2_and_3_refused_after_alignment: its existing assertions stay (the widths 2 and 3 passobs_video_size_valid()and align to 0; 4x3 aligns to 4x2), and it now also expectsobs_video_output_size_valid()to refuse 2 and 3 with heights 2 and 3 and to accept 4x2, 4x3 and 5x3. A new case,output_size_check_edges, expectsobs_video_output_size_valid()to agree withobs_video_size_valid()for every pair of 17 edge sizes (0..8, 1366, 32767..32772, 65536,UINT32_MAX) except the widths 2 and 3.size_check_edgesandalignment_masksare unchanged:obs_video_size_valid()and the alignment masks do not change.test/cmocka/test_video_output_formats.c: the header paragraph that said this file does not drive the width-2/3 edge because the core cannot be used afterwards now describes the fixed behaviour. A new case,small_output_width_refused_before_teardown, resets to NV12 64x32, then tries output sizes 2x32, 3x32, 2x2 and 3x3 (I420), and expects each to returnOBS_VIDEO_INVALID_PARAM, to leave the caller's width as given, and to leave the old video running (obs_get_video()non-null,obs_get_video_info()still NV12 64x32, and a frame arrives). A later reset to I420 64x32 must succeed and produce frames; the case then resets back to NV12 64x32.No other test changes. The other 8 cases of
test_video_output_planand the other 3 oftest_video_output_formatsare unchanged and pass.Headless (private Xvfb, private D-Bus, fresh HOME), OpenGL renderer.
test_video_output_formatssmall_output_width_refused_before_teardown,-1 != -3(the 2x32 reset returnsOBS_VIDEO_FAIL)test_video_output_planobs_video_output_size_validis not declaredobs_get_video()obs_get_video_info()returns false, then SIGSEGV inobs_get_video()obs_get_video_info()returns true,obs_get_video()returns the old video, a later 64x32 reset returns 0test_video_output_formatstest_video_output_planRED → GREEN
test: Expect obs_reset_video() to refuse an output width that aligns to 0. On master,test_video_output_formatsfails 1 of 4 against libobs withOBS_LIBOBS_BACKEND=C, and against the hybrid libobs and libobs-c-reference (HYBRID,OBS_BUILD_C_REFERENCE=ON):small_output_width_refused_before_teardowngetsOBS_VIDEO_FAIL(-1) instead ofOBS_VIDEO_INVALID_PARAM(-3).test_video_output_plandoes not compile on master, because the function it now tests is new.test_video_output_formatspasses 4/4 andtest_video_output_plan10/10 in both lanes and against all three libraries, 3 runs each. The exported symbols of libobs (C backend), the hybrid libobs and libobs-c-reference are identical (1766), andobs_video_output_size_validstays local. Fullctest -j4:OBS_LIBOBS_BACKEND=CHYBRID,OBS_BUILD_C_REFERENCE=ONHYBRID,OBS_BUILD_C_REFERENCE=ONNone failed, skipped or not run; run on their own in the same environment,
test_video_output_formatsran all 4 cases rather than skipping. After the final rebase onto cf4b47b (#1726; it brings #1722, the scene group transform extraction, into libobs), I rebuilt both trees, andtest_video_output_formats,test_video_output_planandtest_scene_group_transformpassed against all three libraries, (4/4, 10/10 and 7/7), and the symbol comparison passed again (1766, identical).uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed. clang-format 23.1 is clean on the changed files.obs_reset_video()from API code.Windows/macOS: the change is portable C in shared libobs code.
test_video_output_formatsis Linux only (it needs a display);test_video_output_planbuilds everywhere and has no cmocka range assertions.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (Fixed upstream bugs, Stability)-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)