Skip to content

bug: libobs: obs_encoder_add_roi accepts upside-down rectangles and a NaN priority #1959

Closed

Description

@rdoupe

Bug

obs_encoder_add_roi() (libobs/obs-encoder.c.h) is meant to refuse ROIs smaller than one 16×16 block and ROIs with a priority outside [-1, 1]. Two inputs get past both checks:

  • Upside-down rectangles. If bottom is above top, or right is left of left, the uint32_t subtractions in the size check wrap to huge values, so the 16×16 minimum passes. The encoder then gets a rectangle with bottom < top in its QP map.
  • NaN priority. NaN < -1.0f and NaN > 1.0f are both false, so a NaN priority is accepted.

obs_encoder_enum_roi() scales each ROI with (uint32_t)((float)roi->top * scale_y). That conversion is undefined behaviour in C when the product is out of the uint32_t range: an ROI far outside the frame, combined with an upscaled output.

The ROI API is reached only from plugins and scripts. Upstream has the same code. Found while scoping the ROI code for a Rust port.

Plan (one PR)

  1. Move the checks and the scaling into libobs/obs-encoder-roi.c.h as hidden helpers. This step changes no behaviour.

  2. Add characterization through the exported API (test_encoder_roi), using a test video encoder with and without OBS_ENCODER_CAP_ROI. It pins:

    • the 16×16 minimum at 15, 16 and 17 in each direction;
    • priorities at -1, 1, just outside the range, and NaN;
    • an upside-down rectangle;
    • the enumeration order (last added first), with and without a scaled size, and with a video size of 0;
    • roi_increment after adding and clearing.
  3. RED, then GREEN:

    • refuse bottom <= top, right <= left and a NaN priority before the size check;
    • saturate the scaled conversion to the uint32_t range.

    No ROI that is valid today changes.

The Rust port of these helpers is a separate, later PR.

Activity

  1. rdoupe commented on Oct 23, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #1959.

  2. added
    claimed
    on Oct 23, 2026
  3. added a commit that references this issue on Oct 23, 2026
    2cf4a19
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

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions