Skip to content

obs-filters: Bound .cube LUT sizes before allocating - #113

Merged
zackees merged 3 commits into
obs-rust:masterfrom
b7216309-jpg:fix/color-grade-lut-size
Oct 10, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
b7216309-jpg:fix/color-grade-lut-size

Conversation

@b7216309-jpg

Copy link
Copy Markdown
Contributor

Fixes #94.

load_1d_lut / load_3d_lut computed 4 * width * width * width in uint32_t from an unchecked LUT_1D_SIZE / LUT_3D_SIZE, as the issue describes. The 1D path is worse than reported: it sizes its buffer as width³ entries but only writes width, so ordinary 1D LUTs break:

LUT_1D_SIZE before
256 allocates 134 MB for 2 KB of data
~1000 asks for ~8 GB
1024, 4096 size wraps to 0, bmalloc(0) → bcrash

Commits

  1. Move the loader to cube-lut.c, unchanged (get_cube_entry, load_1d_lut, load_3d_lut, load_cube_file, enum clut_dimension), so a test can build it without the filter. No behavior change.
  2. test/cmocka/test_cube_lut.c: 3D and 1D LUTs (values are linearized RGBA halves, alpha 1.0), domain lines, an empty domain, a missing size line, a truncated LUT; regressions: LUT_1D_SIZE 1024 loads, and sizes past the spec are refused. The 1024 case crashes until the fix.
  3. Fix:
    • refuse LUT_1D_SIZE > 65536 and LUT_3D_SIZE > 256 (Adobe Cube LUT Specification 1.0) before allocating
    • size the 1D buffer as 4 * width halves
    • compute both sizes in size_t

Draft because there is no C toolchain on my machine; CI is the first build of the new test target (if(TARGET OBS::filters), compiles cube-lut.c and links libobs).

🤖 Generated with Claude Code

b7216309-jpg and others added 3 commits October 10, 2026 14:15
Moves get_cube_entry, load_1d_lut, load_3d_lut and load_cube_file out
of color-grade-filter.c unchanged, with enum clut_dimension, so a test
can build the loader without the filter. No behavior change.

Refs obs-rust#94

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Characterizes load_cube_file (1D and 3D LUTs, domain lines, missing
entries) and adds regressions for LUT sizes:

- LUT_1D_SIZE 1024 must load. The 1D loader sizes its buffer as
  4 * width^3 halves in uint32_t, which wraps to bmalloc(0) here and
  crashes, so this case fails until the next commit.
- sizes past the .cube spec (1D 65536, 3D 256) are refused.

Refs obs-rust#94

Co-Authored-By: Claude Opus 5.5 <[email protected]>
load_1d_lut and load_3d_lut computed `4 * width * width * width` in
uint32_t from an unchecked LUT_1D_SIZE/LUT_3D_SIZE. A LUT_3D_SIZE of
1024 wrapped the size to 0 (bmalloc(0) crashes), and other sizes
wrapped to a small buffer that the entry loop then overran with one
RGBA half per line of the file.

The 1D loader also sized its buffer as width^3 entries though it only
writes width, so any 1D LUT of 1024 or more entries, a common size,
crashed or asked for gigabytes.

- refuse LUT_1D_SIZE above 65536 and LUT_3D_SIZE above 256, the limits
  of the Adobe Cube LUT Specification 1.0, before allocating
- size the 1D buffer as 4 * width halves
- compute both sizes in size_t

Fixes obs-rust#94

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=ad5ba93b87a186699f8f2a78f4ddc4df75ea30b8 secs=339 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791667716,"gate":"rust/all/fmt","host":"linux-x86_64","key":"18bbc38449eef49a3fbb3778f08a0175e0a36480e3a80395b5437414668ae25e","lane":"lint","parents":["daddd099f8eff86f1c0567d4bb465cd6c6d7c4c7"],"secs":143,"stamp":"c754a3701c3a20e0ba40a1a55773e643","tree":"ad5ba93b87a186699f8f2a78f4ddc4df75ea30b8","v":1,"via":"run"}
Ci-Attestation: {"at":1791667716,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"18bbc38449eef49a3fbb3778f08a0175e0a36480e3a80395b5437414668ae25e","lane":"lint","parents":["daddd099f8eff86f1c0567d4bb465cd6c6d7c4c7"],"secs":143,"stamp":"0716ecb230ab17eeb029ec398a2ef631","tree":"ad5ba93b87a186699f8f2a78f4ddc4df75ea30b8","v":1,"via":"run"}
Ci-Attestation: {"at":1791667716,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"8665351ac9e5fb2cc6cd2a58b3cf56f0e7cc89eb6002e30c06f990c26d800d69","lane":"rust-test","parents":["daddd099f8eff86f1c0567d4bb465cd6c6d7c4c7"],"secs":43,"stamp":"113254bf42a12e86c8fe40505821674f","tree":"ad5ba93b87a186699f8f2a78f4ddc4df75ea30b8","v":1,"via":"run"}
Ci-Attestation: {"at":1791667716,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"914f071c859a8f08b6bd722972d7a22652d6e16dfba8716a11e0d9698470e4bc","lane":"tier2-linux","parents":["daddd099f8eff86f1c0567d4bb465cd6c6d7c4c7"],"secs":152,"stamp":"1d3864ce4b9b4e336fdebd7e8526c7e5","tree":"ad5ba93b87a186699f8f2a78f4ddc4df75ea30b8","v":1,"via":"run"}
@zackees
zackees marked this pull request as ready for review October 10, 2026 21:28
@zackees
zackees force-pushed the fix/color-grade-lut-size branch from bb6fa17 to 915498c Compare October 10, 2026 21:28
@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Rebased onto master and fixed three build problems in the earlier commits:

  1. Move commit: cube-lut.c now includes <string.h>. graphics/half.h uses memcpy; the original file got it via obs-module.h, and -Werror rejected the implicit declaration.
  2. Test commit: the test_flv_mux block now ends with its own endif() after the rebase (the CMake nesting was broken).
  3. Test commit: test_cube_lut links m on non-Windows (powf).

RED→GREEN in Tier 2: at the test commit, test_cube_lut dies with SIGTRAP (the bmalloc(0) → bcrash path from #94). With the bounds fix, 41/41 pass with the Rust port OFF and ON. The local gate passes and is stamped. Marked ready.

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.

[crash] obs-filters color-grade: LUT_*_SIZE overflows data_size → heap OOB write driven by .cube file

2 participants