Skip to content

UTF-8 filename truncation crash (upstream #11211) #21

Closed

Description

@icp4u

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:

  1. Generate the filename-format string below and copy the resulting line:

    python3 -c 'print("%CCYY-%MM-%DD %hh-%mm-%ss foo" + "\u200b" * 100 + "bar")'
  2. Paste it into the recording filename-format setting.

  3. Start recording. The upstream report describes an abort with an
    incomplete UTF-8 string error.

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.
  • ./lint and ./unittest passed.
  • The Linux compatibility gate passed all six CTest executables with
    ENABLE_RUST_LIBOBS=OFF and ON; 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions