Repository navigation
libobs/util: Cap UTF-8 truncation back-up at three bytes - #26
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andGenerateSpecifiedFilename(frontend/OBSApp.cpp) builds astd::stringfrom 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 ×0x80must 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-testsaggregate 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