Skip to content

text-freetype2: Fix file text truncation at embedded null bytes #13093

Open
4RH1T3CT0R7 wants to merge 3 commits intoobsproject:masterfrom
4RH1T3CT0R7:master
Open

text-freetype2: Fix file text truncation at embedded null bytes #13093
4RH1T3CT0R7 wants to merge 3 commits intoobsproject:masterfrom
4RH1T3CT0R7:master

Conversation

@4RH1T3CT0R7
Copy link

Strip embedded null bytes from the UTF-8 file buffer before string conversion in the Text (FreeType 2) source plugin.

A new remove_utf8_nulls() helper function is added (mirroring the existing remove_cr() pattern) and called in both load_text_from_file() and read_from_end()
after fread() and before strlen() is used.

Motivation and Context

When "Read from file" is enabled, files containing embedded null bytes (e.g. from certain text editors or encoding artifacts) are truncated at the first \0
because strlen() treats it as end-of-string. This causes only the first line or partial content to be displayed.

Since \0 never appears as a continuation byte in valid UTF-8 sequences, stripping null bytes is safe and requires no changes to downstream rendering code.

Fixes #7595

How Has This Been Tested?

  • Created a test file with embedded null bytes between lines ("Line1\x00\x00Line2\nLine3") — all text now displays correctly
  • Tested with a normal multi-line UTF-8 file (no null bytes) — no regression, displays as before
  • Tested the "Chat log mode" (read_from_end path) with both null-byte and clean files
  • Tested with an empty file — no crash, displays empty as expected

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'Text (FreeType 2)' element only reading first line of file (when 'Read from file' is checked)

1 participant