You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: libobs/util: dstr_left passes NULL to memcpy when pos == 0 #174
Found by the first CI run of the sanitizer workflow (run, PR #171; meta issue linked as parent). Upstream OBS code, unchanged in this fork.
Report (UBSan, test_formatted_filename)
libobs/util/dstr.c:523:3: runtime error: null pointer passed as argument 1, which is declared to never be null
#0 dstr_left libobs/util/dstr.c:523
#1 replace_text libobs/util/platform.c:661
#2 os_generate_formatted_filename libobs/util/platform.c:717
#3 zero_width_space_report_test test/cmocka/test_formatted_filename.c:75
Class
memcpy(NULL, src, 0): UB (C11 7.24.1p2), which the optimizer may use to drop later NULL checks.
Cause
dstr_left calls dstr_resize(dst, pos) and then memcpy(dst->array, str->array, pos). With pos == 0, dstr_resize leaves dst->array NULL. replace_text calls it with pos == 0 whenever a format token (e.g. %CCYY) is at the start of the recording/replay filename format, which is the default format.
Fix
Return early when pos == 0 (after dstr_free(dst) or dstr_resize), or guard the memcpy with if (pos). Check dstr_mid/dstr_right for the same pattern.
Failing test sketch
test_formatted_filename already hits it but keeps passing, because UBSan recovers by default for this check. A Tier 1/2 test calling dstr_left(&d, &s, 0) on an empty dstr under -fno-sanitize-recover=nonnull-attribute goes RED.
Claiming. Plan: RED cmocka test that compiles libobs/util/dstr.c with -fsanitize=undefined -fno-sanitize-recover=undefined and calls dstr_left/dstr_mid/dstr_right with zero lengths, then GREEN guards.
Activity
infra: sanitizer triage catches what the first CI run hid
infra: sanitizer triage catches what the first CI run hid
infra: sanitizer triage catches what the first CI run hid
zackees commentedon Oct 11, 2026
Claiming. Plan: RED cmocka test that compiles
libobs/util/dstr.cwith-fsanitize=undefined -fno-sanitize-recover=undefinedand callsdstr_left/dstr_mid/dstr_rightwith zero lengths, then GREEN guards.test: Fail dstr_left with pos 0 under UBSan (RED)
libobs/util: Skip the copy in dstr_left when pos is 0 (GREEN)