Tk Source Code

View Ticket
Login
Ticket UUID: 965dae4a6dbfd0ebdf29a68af866d6286b85a4cb
Title: X11 font backend: stack buffer overflow (crash) for strings of 1024 or more bytes, e.g. 344 CJK characters
Type: Bug Version: 9.1b1
Submitter: serhiy.storchaka Created on: 2026-09-29 10:53:09
Subsystem: 46. Unix Fonts Assigned To: aku
Priority: 7 High Severity: Critical
Status: Closed Last Modified: 2026-10-13 11:30:13
Resolution: Fixed Closed By: kevin_walzer
    Closed on: 2026-10-13 11:30:13
Description:

With the X11 font backend of 9.1 (HarfBuzz/SheenBidi, unix/tkUnixBidiFont.c), displaying or measuring a string of 1024 or more bytes which is shaped by HarfBuzz crashes the application:

pack [label .l -text [string repeat \u4e2d 400]]
*** stack smashing detected ***: terminated

The same happens with an entry, a text widget line, a canvas text item or font measure. 343 CJK characters (1029 bytes) still work, 344 crash.

X11Shaper_ShapeString() marks cluster boundaries in char seen[1024] indexed by byte offsets up to the length of the string, without checking the size of the array. AddressSanitizer reports a stack-buffer-overflow there. Strings in RTL scripts are limited to 512 glyphs, so they write at most one byte past the array.

9.0 is not affected. 9.1b1 and 9.1.0 RC1 are.

Proposed fix in branch x11-shaper-long-string, with test unixfont-10.1. Found while checking [4eef1fa86e].

User Comments: kevin_walzer added on 2026-10-13 11:30:13:
Merged to trunk. Thank you for the fix.

serhiy.storchaka added on 2026-10-13 05:15:24:

Yes, please. x11-shaper-long-string is the minimal fix for this crash. x11-shaper-unlimited includes it and also removes the 512-glyph limit of [4eef1fa86e], so merging x11-shaper-unlimited fixes both.


kevin_walzer added on 2026-10-13 03:54:30:
Can this branch be merged?

serhiy.storchaka added on 2026-10-01 18:56:58:

Yes. I merged trunk into [x11-shaper-unlimited], so it merges cleanly now. The branch removes the fixed limit on the number of glyphs and cluster breaks, so the 2048 limit is gone after the merge (MAX_GLYPHS is now only the size of a drawing batch).


kevin_walzer added on 2026-10-01 18:32:49:
The branch I committed earlier today has a max_buffer of 2048 - I assume that will be updated once this is merged?

kevin_walzer added on 2026-10-01 18:29:45:
Checking the x11_shaper_unlimited branch, looks good.