Repository navigation
Description
Imported from obsproject/obs-studio#11211.
Original report: obsproject/obs-studio#11211
Originally reported by Penwy on 2024-08-28.
Problem
os_generate_formatted_filename() limits generated filenames to 255 bytes.
The current truncation can split a multibyte UTF-8 character, producing invalid
text. The upstream report describes a crash when starting a recording because
a downstream JSON consumer rejects the incomplete UTF-8 sequence.
For example, a 23-byte ASCII prefix followed by 100 U+200B zero-width spaces
puts the 255-byte cutoff inside a three-byte character. The formatter should
return the complete-character prefix, which is 254 bytes in this case.
Upstream reproduction
Reported with OBS Studio 30.2.2 on Ubuntu 22.04:
-
Generate the filename-format string below and copy the resulting line:
python3 -c 'print("%CCYY-%MM-%DD %hh-%mm-%ss foo" + "\u200b" * 100 + "bar")' -
Paste it into the recording filename-format setting.
-
Start recording. The upstream report describes an abort with an
incomplete UTF-8 stringerror.
The invalid formatter output has also been reproduced locally through a C
regression test; a GUI recording session was not used for local validation.
Acceptance criteria
- Valid UTF-8 input remains valid UTF-8 after filename truncation.
- The existing 255-byte upper bound is retained.
- ASCII filenames and complete UTF-8 characters that fit at the boundary
retain their current behavior. - Regression coverage includes every possible interior cut in two-, three-,
and four-byte UTF-8 characters, plus the reported zero-width-space case.
Decisions
- Scope this issue to UTF-8 corruption at the length limit. The related loss
of filename extensions mentioned in the upstream discussion is separate
and remains unchanged by this fix. - Apply a focused fix to the existing C implementation. This change does not
port the formatter to Rust. - Keep existing C tests, public headers, and exported API signatures intact.
- Run the new C test headlessly by compiling the production formatter source
with a fixture for video metadata.
Verification of the prepared fix
- Before the production fix: two of five new cmocka tests failed.
- After the fix: all five passed with AddressSanitizer, UndefinedBehaviorSanitizer,
and LeakSanitizer. ./lintand./unittestpassed.- The Linux compatibility gate passed all six CTest executables with
ENABLE_RUST_LIBOBS=OFFandON; both builds exported the same 1,752 symbols. - The Windows and macOS validation scripts include the new target; those
platforms have not been tested locally.
Prepared with assistance from Codex (GPT-6).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
test(cmocka): build every test through a cmocka-tests aggregate target
libobs/util: Cap UTF-8 truncation back-up at three bytes