Skip to content

libobs/util: Cap UTF-8 truncation back-up at three bytes - #26

Merged
zackees merged 1 commit into
masterfrom
fix/utf8-truncation-followup
Oct 9, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/utf8-truncation-followup

Conversation

@zackees

@zackees zackees commented Oct 9, 2026

Copy link
Copy Markdown
Member

Follow-up to #23 (issue #21), from an expert review of that PR.

The back-up loop added in #23 could walk all the way to length 0 when bytes 1..255 are all UTF-8 continuation bytes (invalid input, e.g. a hand-edited profile ini). dstr_mid(..., 0) then frees the string, os_generate_formatted_filename() returns NULL, and GenerateSpecifiedFilename (frontend/OBSApp.cpp) builds a std::string from that NULL pointer. The old code never returned NULL.

A UTF-8 character has at most three continuation bytes, so the loop now stops at 252. Valid UTF-8 behaves exactly as before. For invalid input the function still returns a non-NULL result of at most 255 bytes, as the old code did.

Adds invalid_continuation_bytes_test: 'a' + 300 × 0x80 must return non-NULL and 252 bytes.

The review's other finding was that the macOS Tier 2 script didn't build the test. #25 already fixed that with the cmocka-tests aggregate target, so this PR doesn't touch the script.

rust/tools/linux-validate/run.sh: 6/6 pass with OFF and ON, and both builds export the same 1752 symbols. I didn't stamp this with the local gate, because the soldr clippy lane hung on this machine; CI runs the Linux jobs instead.

🤖 Generated with Claude Code

Invalid input made only of continuation bytes could back the truncation
added in #23 up to length 0, making os_generate_formatted_filename()
return NULL (GenerateSpecifiedFilename then builds a std::string from
it). A UTF-8 character has at most three continuation bytes, so stop at
252; valid input is unaffected. Add a regression test.

Follow-up to #21, from review of #23.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zackees
zackees merged commit 9a18e46 into master Oct 9, 2026
22 checks passed
@zackees
zackees deleted the fix/utf8-truncation-followup branch October 9, 2026 08:21
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.

1 participant