hb_ot_layout_lookup_get_glyph_alternates() documents its alternate_glyphs
output as nullable, and the AlternateSubst path was fixed in the previous
commit. The Single-substitution fallback paths (SingleSubstFormat1 and
SingleSubstFormat2, used when the queried lookup is a single-substitution)
had the same defect: they gated the write on
if (alternate_count && *alternate_count)
and then did *alternate_glyphs = glyph_id without checking alternate_glyphs.
Passing a NULL alternate_glyphs with a non-NULL, non-zero count on a covered
glyph therefore wrote through NULL and crashed.
Also require alternate_glyphs to be non-NULL before storing.
Fixes: GHSA-v5mv-8hhw-vff8
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
hb_vector_buf_t::append_base64() sized its output as
unsigned out_len = ((len + 2) / 3) * 4;
which overflows 32-bit for a very large len (len + 2 wraps, and the * 4
wraps for len above ~3.2 GB). len is the attacker-controlled embedded
PNG length on the vector SVG paint path (hb-vector-paint-svg.cc), so a
wrapped out_len under-sizes the buffer while the encode loop still writes
4 bytes per 3 input bytes -- a heap out-of-bounds write.
Compute the group count without the +2 (len / 3 + (len % 3 != 0)) and use
hb_unsigned_mul_overflows()/hb_unsigned_add_overflows() so an oversized
input fails the allocation instead of wrapping. resize_full() already
rejects a size that does not fit in int, so the remaining path is safe.
Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Several public "list getter" APIs document their output array as nullable
(pass NULL to just query the total count without storing anything), but
their implementations gated the copy only on the count pointer:
if (count)
{
+ source.sub_array (start_offset, count)
| hb_sink (hb_array (out, *count)); // writes through out even if NULL
}
Passing a non-NULL count with a NULL output array on a populated table
therefore wrote through the NULL pointer and crashed (SIGSEGV).
Gate each copy on the output pointer as well (the same idiom already used
by hb_color_line_get_color_stops: "if (count && out)"). This is a no-op
when the output array is non-NULL and restores the documented behaviour of
returning the total count when it is NULL. Affected getters:
- hb_ot_color_palette_get_colors (CPAL)
- hb_ot_color_glyph_get_layers (COLR v0)
- hb_ot_meta_get_entry_tags (meta)
- hb_aat_layout_get_feature_types (AAT feat)
- hb_aat_layout_feature_type_get_selector_infos (AAT feat)
- hb_ot_layout_feature_get_characters (GSUB cvXX)
- hb_ot_layout_lookup_get_glyph_alternates (GSUB aalt)
Add test/api/test-ot-nullable-output.c exercising each route with a NULL
output array; every case crashed before this change.
Fixes: GHSA-v5mv-8hhw-vff8
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
hb_pdf_build_indexed_smask() computed its buffer sizes with unchecked
32-bit arithmetic:
unsigned raw_len = (width + 1) * height;
...
out->resize (width * height);
width/height come straight from the attacker-controlled PNG IHDR (the
vector-PDF path re-parses IHDR itself and does not clamp dimensions,
unlike sbix). For width = height = 65536, (width + 1) * height wraps to
65536 and width * height wraps to 0. A crafted IDAT inflating to the
wrapped raw_len passes the length check, the mask buffer is resized to
zero, and the per-pixel loop then writes through out->arrayZ[y*width+x]
and reads past raw -- an out-of-bounds write / NULL-page store and crash.
Reject zero/degenerate dimensions and use hb_unsigned_mul_overflows()
for both (width + 1) * height and width * height before allocating,
sizing the inflate, and indexing. This bounds every subsequent
raw + y*(width+1) and out->arrayZ[y*width+x] access.
Add a CBDT regression seed embedding a 65536x65536 indexed PNG with a
tRNS chunk; it reaches the soft-mask builder through
hb_font_paint_glyph -> CBDT::paint_glyph -> hb_pdf_paint_image and
crashed pre-fix under ASAN/UBSan at hb-vector-paint-pdf.cc:617.
Fixes: GHSA-gmjm-qc3c-qfp8
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The PNG chunk-bounds check in hb_pdf_paint_image() used wrapping
32-bit unsigned arithmetic:
if (pos + 12 + chunk_len > len)
break;
A large attacker-controlled chunk_len (e.g. 0xFFFFFF30) wraps
pos + 12 + chunk_len below len, so a truncated PLTE chunk passes the
check. The oversized plte_len is then trusted during palette
serialization in add_xobject_png_image(), reading far past the input
buffer -- an out-of-bounds read and deterministic crash.
Rewrite the bounds checks to be non-wrapping, relying on the invariant
pos <= len (len >= 8 is checked earlier): gate the loop on
len - pos >= 12 and reject a chunk with chunk_len > len - pos - 12.
This keeps pos <= len across pos += 12 + chunk_len and makes every
in-loop read (chunk header and chunk payload) provably in bounds.
Add a regression seed font that embeds a malformed indexed PNG with an
oversized PLTE length via sbix. It reaches the vector-PDF paint path
through hb_font_paint_glyph -> sbix::paint_glyph -> hb_pdf_paint_image
and crashed pre-fix under ASAN at hb-vector-paint-pdf.cc:222; it now
renders cleanly.
Fixes: GHSA-9m78-3jcg-57f2
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Meson does not version shared libraries on Android, so the generic unix case for generating harfbuzz-config.cmake results in a broken cmake config module.
Assisted-by: OpenCode
Reviewed-by: hlewin@worldiety.de
Tested-by: hlewin@worldiety.de
harfrust 0.12.0 fixes sub-font-unit GPOS advance/placement and AAT
trak tracking differences against the "ot" shaper on variable fonts
(harfbuzz/harfrust#402, #403, #404), by keeping variation-index and
trak deltas fractional instead of pre-rounding them to whole font
units before scaling.
read-fonts is bumped to 0.41.* to match harfrust's requirement; the
currently released skrifa (0.44.0) already depends on read-fonts
^0.41.0, so the dependency graph resolves to a single read-fonts
version.
Verified against the published crates.io packages (harfrust 0.12.0,
read-fonts 0.41.0, skrifa 0.44.0): `meson test -C build` shape and
api suites pass, and `hb-shape --shaper ot` / `--shaper harfrust`
now agree exactly on SFNSItalic.ttf across variation instances,
where they previously differed by sub-font-unit amounts.
Assisted-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Normalize a missing gvar scalar cache to the Null cache before the tuple loop,
so calculate_scalar can use the cache length directly in its fast path.
Keep the fallback from querying a zero-length cache, since that would otherwise
be interpreted as a cached zero scalar.
Clip mask extents can have extreme signed origins after malformed
or heavily transformed outlines. Subtracting the surface origin in
int overflowed for cases such as 0 - INT_MIN.
Keep the mask-to-surface coordinate conversion in int64_t until
after intersecting with the finite clip and surface bounds, then
convert to unsigned only for proven in-range pixels.
Add the minimized OSS-Fuzz seed to the raster fuzzer corpus.
Testing: meson test -C build
Fixes: https://oss-fuzz.com/testcase-detail/4621471331450880
Assisted-by: OpenAI Codex <codex@openai.com>
The D3D11 demo atlas backend advanced its cursor and copied glyph data into the
shadow buffer without checking the fixed atlas capacity. Long sessions could
therefore write past the end of the shadow buffer once the atlas filled.
Match the other demo atlas backends by failing before advancing the cursor when
the requested glyph data does not fit.
Testing: meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>
Mirror Mesons gpu_demo feature in the CMake build with an
AUTO/ON/OFF option. AUTO keeps the demo optional while reporting
missing dependencies, ON makes missing dependencies fatal, and OFF
skips probing and building the demo.
Tested with meson test -C build.
Assisted-by: OpenAI Codex <codex@openai.com>
From the spec: The value c is the character code in question, and i is the segment index in which c appears. If the value obtained from the indexing operation is not 0 (which indicates missingGlyph), idDelta[i] is added to it to get the glyph index. The idDelta arithmetic is modulo 65536.
Forcing this inline speeds up most benchmarks by a few percents,
but at least for the Duployan benchmark, it slows it down by 40%.
This is on Apple silicon.
I had noticed that HarfRust was performing faster on this benchmark,
and after lots of investigation, this force-inline seemed to be the
culprit.
assign_spaces() requires correct topological ordering to find space
roots, so add an additional topo sorting after extension promotion and
table splitting to keep thing sorted
Some projects may need higher C++ standard than C++11. In order not to
force the requirement for the whole project, the C++ standard can be set
at the configure time with -DCMAKE_CXX_STANDARD=20 for example. The
project default takes precedence only when there's no assignment
provided in the command line by setting the default cache value.
There's no need to additionally check for the compiler support when
CMAKE_CXX_STANDARD_REQUIRED is already set.
Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
The Meson-generated CMake package described Windows shared-library
targets with IMPORTED_LOCATION pointing at the import library. CMake
expects DLL imported targets to put the runtime DLL in
IMPORTED_LOCATION and the import library in IMPORTED_IMPLIB.
Generate bindir-aware paths for Windows CMake packages and set both
target properties for all HarfBuzz imported targets. Static and
non-Windows shared builds keep their existing single-location behavior.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6026
Testing:
meson setup build --reconfigure
meson compile -C build
meson test -C build
MinGW cross configure/build/install in /private/tmp
CMake consumer configure/build against harfbuzz::harfbuzz and harfbuzz::subset
Assisted-by: OpenAI Codex
The AAT Lookup null object intentionally starts with format 0xFFFF so
lookup dispatch treats it as unsupported. However, its specialized null
storage was declared as only two bytes, while Null(Lookup<T>) is returned
as a Lookup<T> reference.
Declare enough storage for the current Lookup<T> object size so binding
the null reference is well-defined, while preserving the invalid format
bytes.
Testing: meson test -C build
Assisted-by: OpenAI Codex
Malformed CFF dictionaries can contain real operands outside the
representable range of int. Avoid converting those values directly in
number_t::to_int(), and make arg_stack_t::pop_int() set the interpreter
error when the checked conversion fails.
Also make in_int_range() test the stored double value before converting,
so serialization-side range checks do not depend on an unchecked
conversion.
Testing: meson test -C build
Assisted-by: OpenAI Codex
COLR PaintComposite stores its composite mode as an untrusted table
byte, while the paint callbacks take hb_paint_composite_mode_t. Avoid
casting unsupported table values directly to the public enum. Map
unrecognized values to CLEAR, as required by the COLR table comment,
before calling push_group_for() and pop_group().
Also drop the duplicated COLR-side composite mode enum values and use
the public paint enum names for the accepted values.
Testing: meson test -C build
Assisted-by: OpenAI Codex
GCC LTO can emit weak filename-derived placeholder symbols for empty
translation units, and those symbols can leak from shared libraries on
ELF builds. The stricter check-symbols test added for weak symbols then
catches names such as hb_raster.cc.<hash>.
Remove the empty hb-raster.cc and hb-subset-cff2-to-cff1.cc units from
the build and tracked amalgamations. Move the raster section docs to
hb-raster-image.cc, which remains part of the raster library.
Testing:
meson test -C build
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6021
Assisted-by: OpenAI Codex
* [util] Fix Unicode command line arguments on Windows
GLib g_option_context_parse() converts argv strings from the system ACP via g_locale_to_utf8(), but Windows cmd deliver arguments encoded in the system codepage (ex: CP1252), which cannot represent most Unicode codepoints. This caused non ascii character to be corrupted
For example, for this command, it rendered garbage instead of the emoji:
```
hb-view.exe "C:\Windows\Fonts\seguiemj.ttf" "😋" --output-file=output.png
```
Fix this in all util binaries (hb-ft-raster, hb-info, hb-raster, hb-shape, hb-subset, hb-vector, hb-view) by:
1. Calling g_win32_get_command_line() to obtain correctly UTF-8-encoded arguments from GetCommandLineW().
2. Parsing with g_option_context_parse_strv() which skips the g_locale_to_utf8() conversion for G_OPTION_ARG_STRING entries.
3. Adding G_OPTION_FLAG_FILENAME to the G_OPTION_REMAINING callback entry in main-font-text.hh, so the callback path also skips the locale conversion in strv_mode (see https://gitlab.gnome.org/GNOME/glib/-/blob/8ef2f3ad402daf9fb94615ddef63ceef978fd76f/glib/goption.c#L1305).
* [util] Fix Windows UTF-8 argv parsing
On Windows, GLib's option parser treats argv as encoded in the
system codepage and converts strings with g_locale_to_utf8(). The
utilities need to parse the UTF-8 command line obtained from
GetCommandLineW() instead, otherwise non-ASCII arguments can be
corrupted before reaching the tool logic.
Add a small argv_t wrapper for utility entry points to replace argv
with g_win32_get_command_line() on Windows, and use the strv parser
there so GLib skips the top-level argv conversion. Mark remaining
callback arguments as filenames so GLib also skips callback argument
conversion for positional text and font arguments.
Testing:
meson test -C build
Assisted-by: OpenAI Codex
* [mingw] Update instructions
---------
Co-authored-by: moi15moi <moi15moismokerlolilol@gmail.com>
Use the HarfRust bulk UnicodeBuffer glyph-info append API to populate
the shaping buffer from HarfBuzz glyph infos after one slice cast. This
avoids per-codepoint add calls in the HarfBuzz-to-HarfRust bridge.
Testing: ninja -C build src/rust/libharfbuzz_rust.a
Assisted-by: OpenAI Codex
HarfBuzz language tags are already available as C string bytes.
Pass those bytes directly to HarfRust Language::new instead of
converting through UTF-8 and FromStr.
Testing: ninja -C build src/rust/libharfbuzz_rust.a
Assisted-by: OpenAI Codex
Most shaping calls pass maximum a couple of user features. Store the
converted HarfRust feature list in a SmallVec with the same inline
capacity that HarfRust uses for shape-plan user features, avoiding
a heap allocation for common cases.
Testing: ninja -C build src/rust/libharfbuzz_rust.a
Assisted-by: OpenAI Codex
HarfRust glyph infos and positions are layout-compatible with the
corresponding HarfBuzz buffer structs. Assert that size, alignment,
and visible field offsets match, then copy both arrays directly into
the HarfBuzz buffer instead of translating each glyph field-by-field.
Also, don't truncate hb buffer before resizing it to populate. This
would not zero the private fields (var1/var2, var), but that's not
visible to user nor used later.
Assisted-by: OpenAI Codex
get_base_glyph_paintrecord() looked up the BaseGlyphList with the
reference-returning bsearch(), which yields the all-zero Null object
when the glyph is absent, and then rejected non-matches by comparing
record->glyphId against the requested gid. For glyph 0 the Null
object's glyphId (0) equals the requested gid, so the sentinel was
taken for a real record. .notdef then resolved to a bogus empty paint,
and COLR::get_extents() returned success with 0,0,0,0 instead of
letting hb_ot_get_glyph_extents() fall back to the glyf outline.
Use bfind(), which reports presence directly, so a missing glyph
(including glyph 0) returns nullptr and extents fall back correctly.
This surfaced as a mark-positioning difference: fallback mark
positioning centers a mark using the base and mark glyph extents, so a
.notdef mark over a space was positioned differently from shapers that
report the real outline extents (e.g. fontations/HarfRust).
Testing:
- test/api/test-extents.c: glyph 0 (.notdef, has an outline) now
reports its outline extents; updated the expectation accordingly.
- b/util/hb-shape Noto-COLRv1.ttf -u 0020,0650 now matches
--font-funcs=fontations.
- meson test -C build (246 passed, 1 skipped)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>