Skip to content

libobs/util: Skip the copy in dstr_left when pos is 0 - #222

Merged
zackees merged 2 commits into
masterfrom
fix/174-dstr-left-null
Oct 11, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/174-dstr-left-null

Conversation

@zackees

@zackees zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Fixes #174.

dstr_left() resized the destination to pos and then memcpy'd pos bytes into it. With pos == 0 the array is NULL, and memcpy(NULL, src, 0) is undefined behaviour (C11 7.24.1p2). os_generate_formatted_filename() hits it on every recording whose filename format starts with a token, which includes the default format.

With ENABLE_RUST_LIBOBS=ON, libobs uses the Rust obs-util dstr, which has no raw memcpy. The test still checks the C file directly. Local gate: lint, rust-test and tier2-linux all passed.

zackees and others added 2 commits October 11, 2026 02:15
dstr_left() resizes the destination to pos and then memcpys pos bytes
into it. With pos == 0 the destination array is NULL, and memcpy(NULL,
src, 0) is undefined behaviour. os_generate_formatted_filename() hits
it whenever the format starts with a token (#174). test_dstr_zero_len
compiles dstr.c with UBSan aborting on the first report:

  dstr.c:523:3: runtime error: null pointer passed as argument 1

Co-Authored-By: Claude Opus 5.5 <[email protected]>
dstr_left() now only memcpys when there is something to copy, so it
never passes the NULL array of an empty dstr to memcpy.
test_dstr_zero_len passes under UBSan.

Fixes #174

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=d9265b58d85924f6af1ed9ca903e488a47dc8a0a secs=155 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791710344,"gate":"rust/all/fmt","host":"linux-x86_64","key":"0df2bf9fd1bcc0ef660bcf0a6dc3556735595ddf72c20223cf6d9dee8f539118","lane":"lint","parents":["bfc8c1dc5d93c69cb8316d73c272b998bda7bfcc"],"secs":62,"stamp":"ab00892bc3b3cbdf0a6b670cb9577623","tree":"d9265b58d85924f6af1ed9ca903e488a47dc8a0a","v":1,"via":"run"}
Ci-Attestation: {"at":1791710344,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"0df2bf9fd1bcc0ef660bcf0a6dc3556735595ddf72c20223cf6d9dee8f539118","lane":"lint","parents":["bfc8c1dc5d93c69cb8316d73c272b998bda7bfcc"],"secs":62,"stamp":"5ed7bc8aa223d36d827b3f029e7ff4f2","tree":"d9265b58d85924f6af1ed9ca903e488a47dc8a0a","v":1,"via":"run"}
Ci-Attestation: {"at":1791710344,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"df0baa52b476dd471641ecdd0bf0c33cb12e3844a8e028590f2a47525091ed1c","lane":"rust-test","parents":["bfc8c1dc5d93c69cb8316d73c272b998bda7bfcc"],"secs":33,"stamp":"09861dc608962f9765648120817c3dc5","tree":"d9265b58d85924f6af1ed9ca903e488a47dc8a0a","v":1,"via":"run"}
Ci-Attestation: {"at":1791710344,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"76d009956b90b8068571e386a3104292cdebbdd005cf62a37a0399967457b98b","lane":"tier2-linux","parents":["bfc8c1dc5d93c69cb8316d73c272b998bda7bfcc"],"secs":60,"stamp":"fb7214a9d5b44eed6d4085b558c2c25d","tree":"d9265b58d85924f6af1ed9ca903e488a47dc8a0a","v":1,"via":"run"}
@zackees
zackees merged commit 59e3b11 into master Oct 11, 2026
23 checks passed
@zackees
zackees deleted the fix/174-dstr-left-null branch October 26, 2026 15:43
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.

bug: libobs/util: dstr_left passes NULL to memcpy when pos == 0

1 participant