Skip to content

graphics: Make five math functions safe when dst overlaps an input - #423

Merged
zackees merged 2 commits into
obs-rust:masterfrom
chriscoveries:fix/graphics-alias-ordinary
Oct 13, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
chriscoveries:fix/graphics-alias-ordinary

Conversation

@chriscoveries

Copy link
Copy Markdown
Contributor

Part 1 of #370: the five ordinary same-type alias cases.

Refs #370

Problem

Five exported libobs/graphics math functions store an output lane before
every input lane has been read, so a caller that passes a dst overlapping an
input gets a value that depends on the overlap rather than on the inputs:

Function Head location Failure
bounds_move libobs/graphics/bounds.c:24 re-reads v for the max corner after storing dst->min
bounds_scale libobs/graphics/bounds.c:34 same
bounds_merge_point libobs/graphics/bounds.c:50 same
bounds_get_center libobs/graphics/bounds.c:95 re-reads b->min after storing dst
plane_from_tri libobs/graphics/plane.c:22 reads v1 after writing and normalizing dst->dir

For example, bounds_move(&b, &b, &b.min) moves the max corner from the
already-moved minimum, and plane_from_tri(&p, &p.dir, v2, v3) returns a
distance taken from the normalized direction instead of the vertex. The audit
that found these measured each wrong result directly. The audit's source search
found no caller in libobs, the frontend, the
data layer or the plugins that uses a failing arrangement - a grep, not a proof
across every possible pointer provenance - so this is latent rather than a live
defect. Upstream's own characterization tests for some ports do exercise
arrangements like these, so any whole-tree claim must exclude tests.

No header documents any restriction on the caller's pointers. The Rust port is
the guide: its graphics shims were written to read their inputs in full before
writing dst, and the plane_from_tri shim went further and deliberately
matched the C bug (it detected v1 == &dst->dir and set the distance to
dir·dir, #338) so that the port would agree with the C it was measured
against. That agreement is what the C fix and the shim change remove.

Root cause

Each of the five functions reads an input lane after a store to a lane the
input occupies, when the two share storage. Concretely, for bounds_move:

void bounds_move(struct bounds *dst, const struct bounds *b, const struct vec3 *v)
{
	vec3_add(&dst->min, &b->min, v);   /* if v is &dst->min, v is now the new min */
	vec3_add(&dst->max, &b->max, v);   /* ... so the max moves by the wrong amount */
}

The first vec3_add writes dst->min; when the caller passed v at that
address, the second line's read of v observes the value the first line
wrote. The other four differ only in which lane is written first and which
input is read afterwards - dst->min before v for move/scale/merge-point,
dst before b->min for the center, and dst->dir before v1 for the plane,
where the intervening vec3_norm makes the difference larger.

The copy that fixes it has to happen before the first store, which is what the
snapshot does; nothing about the computation itself is wrong.

Fix

Each fix is a snapshot of the input that a later read would otherwise re-read:
the vector operand for the three vector-taking bounds helpers, b->min for
bounds_get_center, and v1 for plane_from_tri. No expression, operand or
order of operations changes, so non-overlapping results are bit-for-bit
unchanged - measured below rather than asserted.

The Rust side is aligned in the same commit. The bounds shims already read
their inputs before writing, so they needed no change; plane_from_tri
deliberately matched the C bug (see above) and that emulation is dropped, so the
shim reads all three vertices like the other shims in the crate. The plane
characterization test that pinned dir·dir as "Characterized, not endorsed"
now asserts the distance of the original vertex, and additionally that the
aliased call equals a call with a separate destination.

Alternatives considered, and why not:

  • Document a no-alias contract in each header and leave the code alone: the
    bug stays reachable the moment a caller ignores the contract, and it is what
    the Rust port already contradicts.
  • Assert (debug-only) that dst does not overlap an input: turns a wrong value
    into a crash in the same situations the wrong value appears, and still leaves
    release builds computing the wrong answer.
  • Add restrict to the parameters: an overlapping caller becomes undefined
    behavior instead of a wrong value, which is worse, and it does not match the
    Rust port either.
  • Leave the behavior unchanged: these are latent, but the audit measured the
    wrong results directly, and a fix this small has no reason to wait for a
    caller to appear.

How this was tested

  • RED → GREEN: commit 0a6cf0041 is the new tests alone; commit 392f91326
    is the fix. The RED commit fails on master and the GREEN commit passes,
    built with the same local flags: cmake Xcode, Release (-O3 -std=c17),
    ENABLE_RUST_LIBOBS=OFF, no sanitizers, macOS arm64. The Rust suites were
    run with soldr cargo test -p obs-graphics --locked (debug and release).
  • Our own CI: self-hosted x86-64 Linux runners on our fork
    (selfhosted-ci.yml)
    run lint (clang-format 22.1.3, gersemi), Rust Tiers 1–3 (unit, C-oracle
    parity, proptest), and the unchanged cmocka suite with ENABLE_RUST_LIBOBS
    OFF and ON (built natively on Debian 13), including export parity. Each run is
    pinned to the exact commit in this PR:
    https://github.com/chriscoveries/obsrust-fork/actions/runs/38308596686
  • Linux sanitizers (the PR_STANDARD local check, on claw, never the Mac):
    GCC 14, -Werror, ASan with ASAN_OPTIONS=detect_leaks=1. The new cmocka
    test and the obs-graphics Rust tests were both built and run there on the
    GREEN head - commands and results in the Evidence section below.
  • Real runs: not applicable, because no current production caller passes an
    overlapping dst and these are pure-math functions with no I/O, threading or
    platform state - a real OBS run could not reach the changed path. The
    correctness argument is the alias tests, and the unchanged-result argument is
    the compiled differential described below.

Evidence

RED (commit 0a6cf0041, tests only, against the unfixed sources)

test/cmocka/test_graphics_alias_ordinary runs each function twice - on
separate storage, then on the arrangement the audit measured - and asserts the
results are identical:

[==========] tests: Running 5 test(s).
[ RUN      ] test_bounds_move_vec_aliases_min
[  ERROR   ] --- memcmp(&alias, &out, sizeof(alias)) == 0 is not true
[   LINE   ] --- test/cmocka/test_graphics_alias_ordinary.c:45: error: Failure!
[  FAILED  ] test_bounds_move_vec_aliases_min
[ RUN      ] test_bounds_scale_vec_aliases_min
[  ERROR   ] --- memcmp(&alias, &out, sizeof(alias)) == 0 is not true
[   LINE   ] --- test/cmocka/test_graphics_alias_ordinary.c:61: error: Failure!
[  FAILED  ] test_bounds_scale_vec_aliases_min
[ RUN      ] test_bounds_merge_point_vec_aliases_min
[  ERROR   ] --- memcmp(&alias, &out, sizeof(alias)) == 0 is not true
[   LINE   ] --- test/cmocka/test_graphics_alias_ordinary.c:83: error: Failure!
[  FAILED  ] test_bounds_merge_point_vec_aliases_min
[ RUN      ] test_bounds_get_center_dst_aliases_min
[  ERROR   ] --- a->x == b->x is not true
[   LINE   ] --- test/cmocka/test_graphics_alias_ordinary.c:20: error: Failure!
[  FAILED  ] test_bounds_get_center_dst_aliases_min
[ RUN      ] test_plane_from_tri_v1_same_address
[  ERROR   ] --- memcmp(&a->dist, &b->dist, sizeof(a->dist)) == 0 is not true
[   LINE   ] --- test/cmocka/test_graphics_alias_ordinary.c:106: error: Failure!
[  FAILED  ] test_plane_from_tri_v1_same_address
[==========] tests: 5 test(s) run.
[  PASSED  ] 0 test(s).

 5 FAILED TEST(S)

The new Rust tests fail on the same commit:

test plane_from_tri_v1_alias_matches_c ... FAILED
...
thread 'plane_from_tri_v1_alias_matches_c' panicked at rust/obs-graphics/tests/plane_parity.rs:326:5:
alias dist 0.99999994
test move_vec_aliases_dst_min_matches_c ... FAILED
test scale_vec_aliases_dst_min_matches_c ... FAILED
test merge_point_vec_aliases_dst_min_matches_c ... FAILED
test get_center_dst_aliases_min_matches_c ... FAILED

(The four Rust bounds arrangements fail because the C oracle is unfixed; the
plane one fails because the aliased call no longer equals a separate call.)

GREEN (commit 392f91326)

[ RUN      ] test_bounds_move_vec_aliases_min
[       OK ] test_bounds_move_vec_aliases_min
[ RUN      ] test_bounds_scale_vec_aliases_min
[       OK ] test_bounds_scale_vec_aliases_min
[ RUN      ] test_bounds_merge_point_vec_aliases_min
[       OK ] test_bounds_merge_point_vec_aliases_min
[ RUN      ] test_bounds_get_center_dst_aliases_min
[       OK ] test_bounds_get_center_dst_aliases_min
[ RUN      ] test_plane_from_tri_v1_same_address
[       OK ] test_plane_from_tri_v1_same_address
[==========] tests: 5 test(s) run.
[  PASSED  ] 5 test(s).
test_graphics_alias_ordinary: [  PASSED  ] 5 test(s).
test_plane: [  PASSED  ] 17 test(s).
test_bounds: [  PASSED  ] 16 test(s).

Rust: soldr cargo test -p obs-graphics --locked in debug, 31 test binaries,
0 failures - including move_vec_aliases_dst_min_matches_c,
scale_vec_aliases_dst_min_matches_c,
merge_point_vec_aliases_dst_min_matches_c,
get_center_dst_aliases_min_matches_c and the updated
plane_from_tri_v1_alias_matches_c. Each compares the aliased result to its own
non-aliased reference on the Rust side, on the C side, and between the two; the
plane arrangement really shares storage between the destination and v1
(ptr::addr_of!((*dst).dir)). Release is green apart from
norm_matches_c_oracle_finite and norm_matches_c_oracle_any_bits, which fail
on the merge base as well (a pre-existing norm_to_polar trig parity
difference, unrelated to anything here).

Non-overlapping results are unchanged

This is the part a snapshot fix could plausibly get wrong, so it is measured
rather than argued. The method, in full: the five merge-base function bodies are
transcribed byte-for-byte from git show 6318f4274:libobs/graphics/bounds.c and
.../plane.c into a wrapper translation unit, both sides are compiled against the
merge-base headers, every value lane of every input is initialized, both
destination unions are zeroed before each call - which is what makes the
compared padding deterministic - and the results are compared with memcmp over
the whole result object (struct plane's 12 tail bytes are included; they are
zero on both sides). Only the non-overlapping arithmetic can differ, because both
destinations are separate storage.

wrappers.c: the five merge-base bodies, byte-for-byte from git show 6318f4274
/* The merge-base bodies, exported so the probe can call them. Compiled with the
 * merge-base headers, which is what the fixed functions are compared against. */
#include <graphics/bounds.h>
#include <graphics/plane.h>
#include <graphics/vec3.h>

void before_bounds_move(struct bounds *dst, const struct bounds *b, const struct vec3 *v)
{
	vec3_add(&dst->min, &b->min, v);
	vec3_add(&dst->max, &b->max, v);
}

void before_bounds_scale(struct bounds *dst, const struct bounds *b, const struct vec3 *v)
{
	vec3_mul(&dst->min, &b->min, v);
	vec3_mul(&dst->max, &b->max, v);
}

void before_bounds_merge_point(struct bounds *dst, const struct bounds *b, const struct vec3 *v)
{
	vec3_min(&dst->min, &b->min, v);
	vec3_max(&dst->max, &b->max, v);
}

void before_bounds_get_center(struct vec3 *dst, const struct bounds *b)
{
	vec3_sub(dst, &b->max, &b->min);
	vec3_mulf(dst, dst, 0.5f);
	vec3_add(dst, dst, &b->min);
}

void before_plane_from_tri(struct plane *dst, const struct vec3 *v1, const struct vec3 *v2, const struct vec3 *v3)
{
	struct vec3 temp;

	vec3_sub(&temp, v2, v1);
	vec3_sub(&dst->dir, v3, v1);
	vec3_cross(&dst->dir, &temp, &dst->dir);
	vec3_norm(&dst->dir, &dst->dir);
	dst->dist = vec3_dot(v1, &dst->dir);
}
probe.c: drives both copies and compares
/* Differential probe for PR-A: the five snapshot-only alias fixes
 * (bounds_move/scale/merge_point/get_center, plane_from_tri) against the same
 * functions from the merge base, both compiled into one binary. Every result is
 * compared with memcmp over distinct destination storage, so only the
 * non-overlapping arithmetic can differ. */
#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include <graphics/bounds.h>
#include <graphics/plane.h>
#include <graphics/vec3.h>

void before_bounds_move(struct bounds *, const struct bounds *, const struct vec3 *);
void before_bounds_scale(struct bounds *, const struct bounds *, const struct vec3 *);
void before_bounds_merge_point(struct bounds *, const struct bounds *, const struct vec3 *);
void before_bounds_get_center(struct vec3 *, const struct bounds *);
void before_plane_from_tri(struct plane *, const struct vec3 *, const struct vec3 *, const struct vec3 *);

static uint32_t seed = 20261012u;
static float rnd(void)
{
	seed = seed * 1664525u + 1013904223u;
	return (float)((int)(seed % 200001u) - 100000) * 0.00123f;
}

static unsigned long checks, failures;
static const char *mode;

static union {
	struct bounds b;
	struct plane p;
	struct vec3 v;
	char raw[64];
} cur, old;

#define CHECK(label, size, expr)                                                                        \
	do {                                                                                             \
		memset(&cur, 0, sizeof(cur));                                                              \
		memset(&old, 0, sizeof(old));                                                              \
		expr;                                                                                      \
		if (memcmp(&cur, &old, (size))) {                                                          \
			static char seen[40];                                                                \
			if (strcmp(seen, (label)) != 0) {                                                     \
				snprintf(seen, sizeof(seen), "%s", (label));                                 \
				printf("[%s] MISMATCH %s\n", mode, (label));                                  \
			}                                                                                     \
			failures++;                                                                            \
		}                                                                                         \
		checks++;                                                                                  \
	} while (0)

int main(void)
{
	mode = getenv("FP_MODE") ? getenv("FP_MODE") : "?";

	for (unsigned long it = 0; it < 10000; it++) {
		struct bounds bsrc;
		struct vec3 v1, v2, v3;
		struct plane psrc;

		for (unsigned i = 0; i < 8; i++) {
			float x = (i % 4 == 3) ? 0.0f : rnd();
			((float *)&bsrc)[i] = x;
		}
		for (unsigned i = 0; i < 4; i++) {
			float x = (i % 4 == 3) ? 0.0f : rnd();
			((float *)&v1)[i] = x;
		}
		for (unsigned i = 0; i < 4; i++) {
			float x = (i % 4 == 3) ? 0.0f : rnd();
			((float *)&v2)[i] = x;
		}
		for (unsigned i = 0; i < 4; i++) {
			float x = (i % 4 == 3) ? 0.0f : rnd();
			((float *)&v3)[i] = x;
		}

		CHECK("bounds_move", sizeof(cur.b), bounds_move(&cur.b, &bsrc, &v1);
		      before_bounds_move(&old.b, &bsrc, &v1));
		CHECK("bounds_scale", sizeof(cur.b), bounds_scale(&cur.b, &bsrc, &v1);
		      before_bounds_scale(&old.b, &bsrc, &v1));
		CHECK("bounds_merge_point", sizeof(cur.b), bounds_merge_point(&cur.b, &bsrc, &v1);
		      before_bounds_merge_point(&old.b, &bsrc, &v1));
		CHECK("bounds_get_center", sizeof(cur.v), bounds_get_center(&cur.v, &bsrc);
		      before_bounds_get_center(&old.v, &bsrc));

		psrc.dir = v1;
		psrc.dist = rnd();
		CHECK("plane_from_tri", sizeof(cur.p), plane_from_tri(&cur.p, &psrc.dir, &v2, &v3);
		      before_plane_from_tri(&old.p, &psrc.dir, &v2, &v3));
	}

	printf("[%s] checks=%lu failures=%lu\n", mode, checks, failures);
	return failures != 0;
}

The merge-base headers are extracted with git show so the two sides are
compared against the same declarations:

BASE=6318f4274
mkdir -p base/graphics base/util
for n in axisang bounds graphics math-defs math-extra matrix3 matrix4 plane quat srgb vec2 vec3 vec4; do
  git show $BASE:libobs/graphics/$n.h > base/graphics/$n.h
done
git show $BASE:libobs/util/c99defs.h > base/util/c99defs.h
git show $BASE:libobs/util/sse-intrin.h > base/util/sse-intrin.h

for O in 2 3; do for M in off on fast; do
  clang -O$O -std=c17 -fno-strict-aliasing -ffp-contract=$M \
    -Ibase -Ilibobs \
    probe.c wrappers.c \
    libobs/graphics/{bounds,plane,vec3,vec2,vec4,math-extra,matrix3,matrix4,axisang,quat}.c \
    -lm -o probe && FP_MODE=$M ./probe
done; done

Run from a directory that holds the two files above, with the branch's tree at
libobs/ beside them. The same command with gcc instead of clang is the
x86-64 Debian run (no extra include needed there); on arm64, add the SIMDe
include, -I<path-to-obs-deps>/include, because libobs/util/sse-intrin.h
takes __m128 from SIMDe off x86.

Results summary, AppleClang 21 (arm64-apple-darwin27) - twelve runs in all, six
shown here and six more under GCC 14 (Debian 14.2.0, x86-64) with the same
command. Each line is the last line of that run's output.

-O2/off: [off] checks=50000 failures=0
-O3/off: [off] checks=50000 failures=0
-O2/on: [on] checks=50000 failures=0
-O3/on: [on] checks=50000 failures=0
-O2/fast: [fast] checks=50000 failures=0
-O3/fast: [fast] checks=50000 failures=0

Each run is 50,000 comparisons (5 functions x 10,000 inputs); 12 runs, 600,000
comparisons, zero mismatches.

Sensitivity, with the mutation the probe was actually checked against: with
plane_from_tri's snapshot changed to copy v2 instead of v1 (the one input
whose value the distance depends on), the same build and the same mode prints,
literally:

[fast] MISMATCH plane_from_tri
[fast] checks=50000 failures=10000

The six-mode results above are a summary of the corresponding summary lines
(the probe prints one per run); the mutation block is the probe's literal
output, bytes as captured.

Linux sanitizers (claw, GCC 14, -Werror, ASan + LSan)

cmake -S . -B build-asan -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  -DENABLE_UNIT_TESTS=ON -DENABLE_RUST_LIBOBS=OFF \
  -DENABLE_FRONTEND=OFF -DENABLE_SCRIPTING=OFF -DENABLE_BROWSER=OFF \
  -DENABLE_WEBSOCKET=OFF -DENABLE_AJA=OFF -DENABLE_WEBRTC=OFF \
  -DENABLE_NVENC=OFF -DENABLE_QSV11=OFF -DENABLE_VST=OFF -DENABLE_WAYLAND=OFF \
  -DCMAKE_C_COMPILER=gcc \
  -DCMAKE_C_FLAGS="-fsanitize=address -fno-omit-frame-pointer -Werror" \
  -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address"
cmake --build build-asan --target test_graphics_alias_ordinary
ASAN_OPTIONS=detect_leaks=1 ./build-asan/test/cmocka/test_graphics_alias_ordinary
CC=gcc soldr cargo test -p obs-graphics --locked
[  PASSED  ] 5 test(s).

and 31 test binaries with 0 failures for the Rust suite, all on the GREEN
head. The changed C files compile warning-free; the one warning GCC reports in
the build is a pre-existing -Wmaybe-uninitialized in
libobs/util/buffered-file-serializer.c:167, which libobs's own Linux config
downgrades (cmake/linux/compilerconfig.cmake:66), so it does not fail
-Werror.

What this change deliberately does not include

The rest of the audit's table, left to the follow-ups, because each needs
something this PR does not want to carry:

  • calc_torque (libobs/graphics/math-extra.c): a plain snapshot of the
    operand changes non-overlapping results at AppleClang -O3 -ffp-contract=fast - a measured fraction of inputs differ in the last bit,
    because the store-to-reload between the multiply and the add is what keeps them
    apart and a snapshot lets a compiler fuse them. A fix that preserves the bits
    needs the value to round-trip memory explicitly, which is an optimization
    barrier and belongs with the FP-sensitive group rather than in a correctness
    PR.
  • quat_mul, vec3_rotate, vec3_transform3x4: fixing these while keeping
    non-overlapping results identical requires the same kind of barrier, and the
    barriers cost measurable time. For a latent aliasing bug with no known caller
    that tradeoff needs a stated FP contract, not silence inside a correctness PR.
    Deferred pending a maintainer decision on the project's FP policy - what
    contraction mode the shipped builds should promise, and whether the ports and
    the C should both honour it.
  • polar_to_norm, gs_u8x4_to_float4, matrix3_scale/mirror/mirrorv,
    quat_from_matrix3/matrix4
    : cross-type storage overlap and the srgb
    same-base arrangement, which is a broader API-contract question.
  • get_3x3_submatrix (libobs/graphics/matrix4.c): the audit flagged it,
    but it is private, both callers pass distinct local arrays, and the arrangement
    is unreachable from the public API. Untouched here; it should be its own small
    PR with a private-helper regression if a maintainer wants it.

Compatibility & risk

  • No signature, struct layout, export or public-header change.
  • No in-tree caller uses a failing arrangement, so no behavior changes for
    existing call sites: every existing characterization test passes, the only
    edit being the plane test whose subject this PR changes.
  • With ENABLE_RUST_LIBOBS=ON the Rust shims are what the cmocka tests
    exercise; both configurations behave the same for these functions.
  • Cross-type same-base storage is not covered: the tests use OBS's
    -fno-strict-aliasing configuration, and their success does not create a
    portable arbitrary-overlap C contract.
  • Platforms not tested: Windows. The evidence above is macOS arm64
    (AppleClang 21) and Linux x86-64 (GCC 14); MSVC's code generation for these
    functions has not been exercised. The changed code has no platform-specific
    branches.

Status

  • Branch: fix/graphics-alias-ordinary, two commits on top of master
    (6318f4274): RED 0a6cf0041, GREEN 392f91326.
  • Local: RED and GREEN verified (5 failed, exit 5, then 5 passed, exit 0), the
    twelve-run differential clean on AppleClang 21 and GCC 14, debug suite green,
    lint clean.
  • Fork CI on the head, run
    https://github.com/chriscoveries/obsrust-fork/actions/runs/38328937735
    (pinned to 392f913263bb208a0479443bf7a4894f240a19e9: gate and tier2
    success
    ), plus https://github.com/chriscoveries/obsrust-fork/actions/runs/38308596686
    for the mac job (also success; mac was skipped in the later run by
    design). From that run's own log:
    • ENABLE_RUST_LIBOBS=OFF: 100% tests passed, 0 tests failed out of 103
      (the new suite included, #64: test_graphics_alias_ordinary ... Passed),
      100% tests passed, 0 tests failed out of 26 in the timed partition,
      100% tests passed, 0 tests failed out of 9 in the exclusive partition.
    • == [OFF] FLAKY (failed once, retried): test_deinterlace_2x_field_order -
      test_deinterlace_2x_field_order failed its first attempt in this mode and
      passed on the retry; the same executable fails the same way on unrelated
      branches (run
      38288281479
      at f855e274d). The run is green because of the retry, not because the
      failure was ignored.
    • ENABLE_RUST_LIBOBS=ON: 100% tests passed, 0 tests failed out of 103,
      26/26, 9/9, and the same == [ON] FLAKY (failed once, retried): test_deinterlace_2x_field_order.
    • == libobs exported symbols, OFF vs ON / IDENTICAL (1766 symbols).

Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.

chriscoveries added 2 commits October 12, 2026 18:22
The five libobs/graphics math functions this branch repairs re-read an
input after storing an output lane, so a dst overlapping an input depends
on the overlap. Three commitments, all failing on master:

- test/cmocka/test_graphics_alias_ordinary.c: runs bounds_move,
  bounds_scale, bounds_merge_point, bounds_get_center and plane_from_tri
  twice, once on separate storage and once on the arrangement, asserting
  the results are identical. 0 of 5 pass on master.
- rust/obs-graphics/tests/bounds_parity.rs: the same four arrangements on
  the Rust shims, each comparing the aliased result with the non-aliased
  one on the Rust side, the C side and between the two.
- rust/obs-graphics/tests/plane_parity.rs: the plane arrangement now also
  compares the aliased result against a call with a separate destination,
  which the C oracle on master does not satisfy (it returns dir·dir for
  the distance).

The plane comparison is on dir's lanes and dist, not the struct, because
struct plane has 12 bytes of tail padding.
…REEN)

bounds_move, bounds_scale, bounds_merge_point and bounds_get_center read
their vector operand, or b->min, again after writing dst->min, so a caller
that passes a destination it also reads from gets a value that depends on
the overlap. plane_from_tri reads v1 after writing dst->dir, so a v1
sharing storage with the destination yields a distance taken from the
normalized direction instead of the vertex.

Each fix is a snapshot of the input that the later read would otherwise
re-read: the operand for the four bounds helpers, b->min for the center,
and v1 for the plane. No expression, operand or order of operations
changes, so non-overlapping results are bit-for-bit unchanged.

The Rust port is aligned in the same commit. The bounds shims already read
their inputs before writing, so they needed no change; plane_from_tri had
copied the C bug on purpose - it detected `v1 == &dst->dir` and set the
distance to dir·dir (obs-rust#338) - and that emulation is dropped, so the shim
reads all three vertices like every other shim in the crate. The plane
characterization test that pinned dir·dir ("Characterized, not endorsed")
now asserts the distance of the original vertex and that the aliased call
equals a call with a separate destination.

GREEN: test_graphics_alias_ordinary 5 passed, 0 failed (exit 0), and the
existing test_plane (17) and test_bounds (16) suites pass, in the same
Release build as the RED commit's 0-passed/5-failed run.

Local-Gate: v1 tree=e491b7e0aad43f87b98f9f54ca8b8692c5dbc748 secs=176 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791854742,"gate":"rust/all/fmt","host":"linux-x86_64","key":"80aee80b302f28ff1fe2588d45fee172121d392fe232b8cd6d19ea0a88a01237","lane":"lint","parents":["6161f0666d81c3fd5bf9d8644a44039d58299a38"],"secs":39,"stamp":"c13a375d0f58e6abcbb9dd0201d059f0","tree":"e491b7e0aad43f87b98f9f54ca8b8692c5dbc748","v":1,"via":"run"}
Ci-Attestation: {"at":1791854742,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"80aee80b302f28ff1fe2588d45fee172121d392fe232b8cd6d19ea0a88a01237","lane":"lint","parents":["6161f0666d81c3fd5bf9d8644a44039d58299a38"],"secs":39,"stamp":"5b1f1dbec523079acd2b0129aa059db5","tree":"e491b7e0aad43f87b98f9f54ca8b8692c5dbc748","v":1,"via":"run"}
Ci-Attestation: {"at":1791854742,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"e0fc8277f27f5efe797856b0956c6e8cac844384103903d31f8fb9d4a48a4819","lane":"rust-test","parents":["6161f0666d81c3fd5bf9d8644a44039d58299a38"],"secs":64,"stamp":"f2fdd9558f3efd1fa3330dd7ce1fe7a9","tree":"e491b7e0aad43f87b98f9f54ca8b8692c5dbc748","v":1,"via":"run"}
Ci-Attestation: {"at":1791854742,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"2baf904178cd0711f9792e8a2e6792204bdf510ba3bf5ec4ce186d8a5f120758","lane":"tier2-linux","parents":["6161f0666d81c3fd5bf9d8644a44039d58299a38"],"secs":73,"stamp":"1ec76fb4a267a1895436e7a81eaeb3bc","tree":"e491b7e0aad43f87b98f9f54ca8b8692c5dbc748","v":1,"via":"run"}
@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Verified locally (zccache bypassed for the Rust side):

  • RED 0a6cf00: test_graphics_alias_ordinary fails 5 (bounds_get_center/merge_point/move/scale with dst aliasing min, plane_from_tri_v1_same_address); obs-graphics bounds_parity fails 4 of 6
  • GREEN 392f913: Tier 2 136/136 OFF and ON; bounds_parity 6/6, plane 17/17, plane_parity 2/2
  • The change to the existing test_plane.c case is intended: it had characterized the aliased plane_from_tri dist (0.99999994, "Characterized, not endorsed"), and now asserts the same plane as a separate destination. The Rust shim changes to match, so C and Rust stay at parity.
  • Rebased on master, local gate passed; pushed as 5d5de3c.

@zackees
zackees force-pushed the fix/graphics-alias-ordinary branch from 392f913 to 5d5de3c Compare October 13, 2026 01:25
@zackees
zackees merged commit 080f761 into obs-rust:master Oct 13, 2026
23 checks passed
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.

2 participants