Commit Graph
10 Commits
Author SHA1 Message Date
Behdad Esfahbod b1316bce52 [uniscribe] Read font directories from the sanitized original (#6488)
* [uniscribe] Read font directories from the sanitized original

Renaming a face's name table record can change another face's
header when TTC directories overlap. Parsing the edited copy then
uses table counts and offsets that were never sanitized. Find each
record in the original blob and edit the copy at that byte offset,
keeping both directory reads and record writes within validated data.

Add a bounded overlapping-collection regression and a non-overlapping
control, gated on Uniscribe support. The original renamer fails under
ASan; the patched public-API test passes with Windows stand-ins.
Ordinary TTF, TTC, and dfont outputs remain byte-identical. MinGW
builds the 64-bit Windows executable and the 32-bit backend, including
HB_NO_OT_FONT. Windows execution was unavailable. The full native
Meson suite passes (274 tests).

Reported by Anthropic's OSS Scanner as ANT-2026-2VV35K9M.

Assisted-by: OpenAI Codex

* [uniscribe] Don't create font data without face data

When face-data creation fails -- eg. AddFontMemResourceEx() rejects a
malformed font and returns NULL -- face->data.uniscribe is left NULL.
populate_log_font() then dereferences it
(font->face->data.uniscribe->face_name) and crashes.  This is reachable
from the public hb_uniscribe_font_get_hfont() and from shaping with any
font GDI declines, not just the overlapping-TTC case.

Bail out of _hb_uniscribe_shaper_font_data_create() when face data is
NULL, matching _hb_coretext_shaper_font_data_create().

This is what made the new test-uniscribe regression crash on the
Windows CI jobs: Wine reported "page fault on read access to
0x0000000000000010", ie. a NULL + offsetof(face_name) read.  Verified
by cross-compiling with MinGW and running the test under Wine: it hits
the same 0x10 page fault without this change and exits cleanly with it.

Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>

* [directwrite] Don't create font data without face data

Same NULL face-data dereference as the uniscribe backend: when
_hb_directwrite_shaper_face_data_create() fails (dw_face_create()
returns NULL for a font DirectWrite rejects), face->data.directwrite is
left NULL.  _hb_directwrite_shaper_font_data_create() then calls
fontFace->QueryInterface() through that NULL pointer and crashes.

Bail out when face data is NULL, matching the uniscribe and coretext
backends.

Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 17:15:02 -06:00
Garret Rieger 863c53818b [directwrite] Fix cluster mapping OOB access, heap overflow, and UAF (#6252)
In the DirectWrite shaper, vis_clusters was allocated from the scratch
buffer with a static size based on Uniscribe scratch math (glyphs_size).
This caused three memory safety issues:

1. vis_clusters was indexed using log_clusters, which stores user
   cluster IDs rather than glyph indices, allowing arbitrary
   out-of-bounds array access. In DirectWrite, the character-to-glyph
   mapping is returned in clusterMap, not log_clusters.
2. If glyphCount exceeded glyphs_size, the initialization loop
   overwrote past the allocated scratch buffer.
3. buffer->ensure(glyphCount) could reallocate buffer->pos,
   invalidating the scratch-allocated vis_clusters before its values
   were read into info->cluster (use-after-free).

Fix this by allocating vis_clusters dynamically as an hb_vector_t
sized to glyphCount, and correctly mapping clusters using clusterMap
with bounds checks.

Assisted-by: Gemini
2026-09-10 16:12:36 -06:00
Behdad Esfahbod 07fe5d55a6 [directwrite] Avoid implicit double promotion
The RTL-safe offset is intentionally double precision, while the font
scale is a float. Cast the scale explicitly before multiplying so GCC's
-Wdouble-promotion does not warn about the intended conversion.

Testing: MinGW DirectWrite build with -Wdouble-promotion
Testing: meson test -C build --print-errorlogs

Assisted-by: Codex <codex@openai.com>
2026-08-18 04:28:08 -06:00
Behdad Esfahbod c91e0cace0 Merge pull request #6162 from harfbuzz/fix-directwrite-libstdcxx
[directwrite] Avoid C++ allocation runtime
2026-08-17 15:13:59 -06:00
Behdad Esfahbod 7e444d887a [directwrite] Avoid C++ allocation runtime
DirectWrite used scalar and array new/delete for its COM helpers and
shaping buffers. This left operator new/delete references in MinGW
static and amalgamated builds, forcing C consumers to link libstdc++.

Use HarfBuzz allocators and containers instead, propagate allocation
failures from text analysis, and let Meson use the normal C linker.

Tested with MinGW Meson and CMake DirectWrite builds, a C-linked
amalgamation, and the full Meson test suite.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6160
Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-13 19:32:24 -06:00
Behdad Esfahbod 8c67f8315b [directwrite] Clamp shaped positions
DirectWrite returns floating-point advances and offsets which were
stored and scaled through unchecked integer conversions. Clamp the
scratch values and final scaled positions, and negate RTL offsets in
floating point.

This is part of the complete position-overflow fix for issue #6151.

Testing: meson test -C build --print-errorlogs

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:06:27 -06:00
Behdad Esfahbod ba709a385e [dwrite] Fix cast-align error-warning
Fixes https://github.com/harfbuzz/harfbuzz/issues/5197
2025-03-24 02:08:04 -06:00
Behdad Esfahbod 91bd6bf0df [directwrite] Make variations work on font-funcs 2025-03-22 16:38:56 -06:00
Khaled Hosny 686503e2e0 [directwrite] Copy font variations when shaping 2025-03-20 01:59:56 +02:00
Behdad Esfahbod db8d099d4d [dwrite] Split shape code into its own file 2025-03-15 13:59:16 -06:00