Skip to content

bug: libobs/obs-ffmpeg: VAAPI crashes when the first encoded packet holds only headers (upstream #13316) #216

Closed

Description

@rdoupe

Upstream OBS bug, reported by vicho314 in obsproject/obs-studio#13316. Code unchanged in this fork.

Location

libobs/obs-nal.c:27: obs_nal_find_startcode() computes end - 3 and reads from it without checking for an empty buffer, reached from obs_avc_keyframe() / obs_hevc_keyframe() called by plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c (vaapi_encode_internal).

Class

NULL pointer dereference (crash).

How it is reached

If the VAAPI encoder's first packet holds only parameter sets (SPS/PPS, or VPS/SPS/PPS for HEVC), obs_extract_avc_headers() moves all of it into the header, leaving the packet buffer NULL with size 0. The keyframe check then runs on (NULL, 0) and reads address 0. The reporter's crash (AMD Mullins, radeonsi) has the trace obs_nal_find_startcode(p=0x0, end=0x0) ← obs_avc_keyframe ← vaapi_encode_internal ← vaapi_encode_tex.

Reproduced on a Radeon 680M by forcing a header-only first packet (a shim on avcodec_receive_packet): H.264 and HEVC texture encoding segfault with the same backtrace. The Rust port of the NAL code already returns early on end <= p; only the C build crashes.

Proposed fix and failing test

Fix: obs_nal_find_startcode() returns end when end <= p (matching the Rust port), and the VAAPI encoder skips a packet whose data is empty instead of passing NULL on.

RED tests (cmocka): test_avc_keyframe_empty in test_avc_parse.c (a header-only SPS+PPS packet through obs_extract_avc_headers(), then the keyframe check, plus (NULL, 0)) and test_hevc_keyframe_empty in test_hevc.c both crash today with SIGSEGV. With the fix both pass, and with the forced header-only first packet all four VAAPI encoders (ffmpeg_vaapi, ffmpeg_vaapi_tex, hevc_ffmpeg_vaapi, hevc_ffmpeg_vaapi_tex) record cleanly.

Activity

  1. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_avc_keyframe_empty and test_hevc_keyframe_empty (both crash today).
    2. GREEN: empty-buffer guard in obs_nal_find_startcode() (like the Rust port) and skip empty packets in the VAAPI encoder.
      PR within the hour.
  2. added 3 commits that reference this issue on Oct 11, 2026
    169f308
    ee9d211
    9ab9779
  3. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    @vicho314 you reported this in obsproject/obs-studio#13316, so a heads-up: it's fixed here in obs-rust by #218.

    Cause: when the VAAPI encoder's first packet contains only the stream headers (SPS/PPS, or VPS/SPS/PPS for HEVC), OBS moves all of it into the header and is left with an empty packet. The keyframe check then read address 0, which is the obs_nal_find_startcode(p=0x0, end=0x0) frame in your trace. The NAL scanner now stops on an empty buffer and the encoder skips empty packets. Forcing a header-only first packet on a Radeon 680M gave your exact backtrace before the fix, and clean recordings on all four VAAPI encoders after it.

    Workaround on stock OBS: use a software encoder (x264) instead of VAAPI.

    obs-rust is an AI-assisted fork of OBS; on Arch it's obs-studio-rust-git in the AUR.

    If you can try it on the Mullins machine, a short reply here on whether VAAPI recording starts would really help, especially if it still crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions