Skip to content

bug: obs-graphics: writer parity test feeds a dstr with a NUL #3802

Closed

Description

@rdoupe

What happens

shader::effect_parser_writer_parity::called_functions (rust/obs-graphics/tests/shader/effect_parser_writer_parity.rs, from the writer port in #3769) fails now and then: proptest finds a case where the Rust writer and the C writer write different shader strings. It failed in a local ./unittest run on a branch that changes no Rust and none of the writer's C.

minimal failing input: Model { params: [MParam { ty: [97], name: [97], is_const: false, is_uniform: false, count: 1, written: false }], structs: [], funcs: [MFunc { name: [97], ret: [97], mapping: None, contents: [123, 125], .. }], samplers: [], call: Some([([97], 0), ([40], 0), ([41], 0)]), prefix: Some(([0], 0)) }
left (Rust):  "\0a a[1];\na a()\n{}\n\na main()\n{\n\treturn a();\n}\n"   len 44
right (C):    ";\na a()\n{}\n\na main()\n{\n\treturn a();\n}\n"           len 37
seed: cc d775b1a919540b7ca0889e7c0df1132e1a8ae4d48a25c4a412302bcd64a9f1ad

Why

The model's prefix, the text already in the caller's struct dstr before ep_makeshaderstring() appends to it, is generated from any bytes (effect_parser_writer_parity.rs ~290):

prop::option::weighted(0.2, (prop::collection::vec(any::<u8>(), 1..6), 0usize..8)),

so it can hold a NUL byte while len counts past it. A dstr never looks like that: its len is the length of its text up to the terminating NUL, and the dstr helpers the C writer calls rely on that (here the C's result loses the a a[1] it wrote after the NUL). The compile step always passes an empty dstr, so no real input reaches this; the difference is the generator's, not the writer's.

Proposed fix

Generate prefix bytes without NUL (prop::collection::vec(1u8..=255, 1..6)), keeping the prefix's other cases, and check the case above passes. Neither writer changes.

Test

The seed above fails on master today; with the generator fixed, the same model can no longer be generated, and called_functions and random_parsers pass at the full case count.

Activity

  1. added
    bug
    P2
    size:S
    on Nov 7, 2026
  2. rdoupe commented on Nov 7, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: the writer parity test's NUL-bearing dstr prefix

    1. RED: pin the failing case from the issue (the NUL-bearing prefix model) as a deterministic regression case, plus a check that the model generator never emits a prefix holding a NUL; both fail on master.
    2. GREEN: generate prefix bytes from 1u8..=255, keeping the prefix's length, spare capacity and None cases. Neither writer changes.
    3. Run called_functions and random_parsers at the full case count, plus the usual local gates.

    PR expected within a few hours.

  3. added
    ready
    on Nov 7, 2026
  4. rdoupe commented on Nov 7, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by #3811 (merged through the merge queue). The writer parity test now draws its dstr prefix bytes from 1..=255, so a prefix can no longer hold a NUL while the length counts past it; a new test, prefix_is_dstr_text, checks 20,000 prefixes from a fixed seed. Neither writer changed, because the difference came from the test's generator and not from the writers; real input never reaches it, since the compile step passes an empty dstr.

    Left: nothing. There is no follow-up issue.

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

Metadata

Metadata

Assignees

Labels

P2bugreadysize:S

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions