Repository navigation
Description
Upstream report: obsproject/obs-studio#12213 by walker-WSH (Windows, OBS 31.0.3): a stream fails to connect, Output Resolution is changed, and the next Start Streaming crashes in obs_x264_update() → obs_encoder_get_width() on a freed video_t. walker-WSH posted an updated analysis on 2026-10-16 (encoders left initialized by an output that never started, plus a proposed obs_reset_video() change).
Our #236 (in 0.1.0-beta.20261014) already shuts those encoders down after a failed connection, and the exact steps from the report no longer crash here (see below). The underlying cause is still there, though: obs_reset_video() frees the video mixes, but video encoders keep the old video_t. #470 moved raw outputs to the new mixes; encoders were left out. Three other paths crash the release.
Location
libobs/obs.cline 1652,obs_reset_video(): frees every mix (obs_free_canvas_mixes()), thenrepoint_outputs()(line 1623) moves raw outputs to the new mixes. Nothing does this for encoders, so every video encoder keeps thevideo_tit got fromobs_encoder_set_video().- The guard at line 1658 only checks
obs_video_active(). An output that is still connecting has initialized its encoders, but no encoder is active yet, so the reset goes through under it. libobs/obs-encoder.cline 1271:obs_encoder_set_video()refuses a newvideo_twhile the encoder is initialized. An encoder left initialized by an output that never started keeps the freed one on the next start too.- Readers of the stale pointer:
obs_encoder_get_width/height()(line 1121), and through itobs_output_get_width/height()of encoded outputs (libobs/obs-output.cline 1277, called by obs-websocket'sGetOutputList); the encoder'supdate()(x264update_params()); andrtmp_output's metadata (plugins/obs-outputs/flv-mux.cline 210). - An encoder stays initialized when
start()initializes the encoders and then returns false.ffmpeg_muxerdoes this when the recording folder is not writable (plugins/obs-ffmpeg/obs-ffmpeg-mux.clines 387 and 425). Nothing shuts those encoders down; bug: libobs: encoders (and their NVENC session) stay initialized after a stream fails to start (upstream #10651) #236 covers onlyobs_output_signal_stop().
Reproduced in 0.1.0-beta.20261014
The released AppImage, headless (private Xvfb and D-Bus, fresh profile, x264, Simple output), driven over obs-websocket. All endpoints are local: a refused port, an ffmpeg RTMP listener, a TCP relay in front of it. A test module clicks the error dialogs away.
| Steps | 0.1.0-beta.20261014 | master (266b651), ASan build |
|---|---|---|
Stream to the listener, stop, SetVideoSettings (output 480x270), GetOutputList |
SIGSEGV, 4 of 4 runs (and 2 of 2 when the stream had failed to connect instead) | heap-use-after-free in video_output_get_width() ← GetOutputList; freed by obs_reset_video() |
Start Recording into a folder that cannot be written (fails), SetVideoSettings, fix the folder, Start Recording |
SIGSEGV, 4 of 4 | heap-use-after-free in x264 update_params() ← SimpleOutput::StartRecording(): walker-WSH's stack |
Start Streaming to a server that accepts TCP but answers only after 0.2-1 s; SetVideoSettings while it connects; the connection then succeeds |
SIGSEGV, 4 of 4 | heap-use-after-free in build_flv_meta_data() ← rtmp-stream send_meta_data() |
walker-WSH's steps: Start Streaming to a refused port (plain and IPv6 Only, reconnect on and off); stream, receiver killed, Stop while reconnecting; reconnect gives up. Then SetVideoSettings (right after STOPPED or up to 1 s later) and a working stream |
0 crashes in 120 cycles (Simple and Advanced) | clean in 80 cycles, no ASan report |
SetVideoSettings while reconnecting |
refused by the frontend (outputHandler->Active()), no crash |
- |
So #236 holds for the reported steps, and the bug remains for an encoded output's size after any reset, for a recording that failed to start, and for a reset during a connection.
Class
Crash (use-after-free) in a common flow: a resolution change after a recording into a bad folder failed, any obs-websocket client that lists outputs after SetVideoSettings (possibly the unexplained GetOutputList crash in #476), and a resolution change through the websocket while a stream connects. No data loss.
Proposed fix
In obs_reset_video(), before the mixes are freed, unbind every inactive video encoder that holds one of their video_t. One that is still initialized is shut down first, while its video is valid (walker-WSH's proposal). After the reset, bind it to the new mix of the same canvas, as repoint_outputs() does for raw outputs. Also refuse the reset (OBS_VIDEO_CURRENTLY_ACTIVE) while an output is starting, reconnecting or delaying, as while one is active.
RED: a new cmocka test, test_encoder_video_reset, with a counting encoder (it reads its size at create and update, as x264 does) and outputs that fail like ffmpeg-mux and rtmp_output. It checks the encoder's video_t against the live one before anything reads it, with the freed address pinned so the allocator cannot reuse it. Its 5 cases (an encoder after a normal stop, after a failed start, after a failed connection, with a frame rate divisor, and a reset while an output connects) all fail today, in both lanes, with and without ASan.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 16, 2026
Claiming: this issue.
Upstream report obsproject/obs-studio#12213 by walker-WSH. Our #236 already covers the reported steps (a failed connection); this fixes the rest in libobs:
test_encoder_video_reset. A counting encoder and outputs that fail like ffmpeg-mux (start() fails after the encoders were initialized) and rtmp_output (the connection fails, or is still pending). Afterobs_reset_video()the encoder must hold the livevideo_t(checked before anything reads it, with the freed address pinned), report the new size, and be created for it on the next start. A reset while an output is still connecting must be refused. All 5 cases fail today.obs_reset_video()unbinds inactive video encoders from the old mixes (shutting down one that is still initialized while its video is valid), binds them to the new mix of the same canvas afterwards, asrepoint_outputs()does for raw outputs, and refuses the reset while an output is starting, reconnecting or delaying.GetOutputListafterSetVideoSettings, a recording retry after a failed start, a reset while a stream connects, and walker-WSH's stream steps) on an ASan build of the branch.rdoupe commentedon Oct 16, 2026
@walker-WSH you reported this upstream in obsproject/obs-studio#12213 (a crash on the freed
video_tafter a failed connection and an Output Resolution change). Heads-up that it's fixed here in obs-rust: #1109 merged today with a regression test.Your analysis was right, and your proposal is what the fix does.
obs_reset_video()now shuts down inactive encoders that are still initialized before it frees the old video mixes. It also moves every video encoder to the new mix of the same canvas, the way raw outputs already move, soobs_encoder_set_video()no longer has to replace an initialized encoder's video. Your exact steps had already stopped crashing here with an earlier change (#236), which shuts down the encoders of a stream that fails to connect. But the same freed pointer crashed our release (0.1.0-beta.20261014) in three other ways, 4 of 4 times each:GetOutputListafterSetVideoSettings, once a stream or recording had run (the encoder kept the oldvideo_teven when it was not initialized);start(), so nothing shuts them down. Your stack, through x264's update;With the fix, under AddressSanitizer: 120 cycles of these cases and of your steps (refused port, IPv6 Only, reconnect on and off, stop while reconnecting), with no report.
It will be in the next obs-rust daily release after 0.1.0-beta.20261014: https://github.com/obs-rust/obs-studio/releases (Windows, macOS and Linux builds; on Arch it's
obs-studio-rust-gitin the AUR). obs-rust is an AI-assisted fork of OBS.We tested on Linux only. The change is in libobs code shared by all platforms, but we couldn't try it on Windows with your setup. If you get a chance to try your steps there, a reply here would really help.
libobs: Move video encoders to the new video mix on obs_reset_video (o…