Reduce to one templated hb_qsort, one templated qsort() on
hb_array_t/hb_vector_t, plus the no-arg qsort() that casts
Type::cmp to resolve ambiguity.
Convert all external call sites to lambdas so comparators
inline everywhere. Remove the void*-arg overload and the
plain function-pointer overload.
225 tests pass, 0 failures.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Make sort_r_simple and sort_r_cmpswap take the comparator as a
template parameter instead of a function pointer. This allows
lambdas and functors to inline into the sort, avoiding the
indirect-call overhead.
The function-pointer overloads remain for backward compatibility
and for the __OPTIMIZE_SIZE__ / qsort_r paths.
17% speedup on GPU encode benchmark (NotoSansCJK).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three declarations in hb-gpu.h still had *glyph instead of *draw.
Add SECTION doc block in new hb-gpu.cc for gtk-doc.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add an hb_array_t::qsort overload that takes a comparator with a
void* context argument, forwarding to hb_qsort's existing qsort_r
support. Use it in the GPU encoder to eliminate the last std::
usage from library code.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use hb_min/hb_max instead of std::min/std::max, and
INT16_MIN/INT16_MAX instead of std::numeric_limits.
Only std::sort remains (needs lambda captures).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
INFINITY is float; assigning to double triggers -Wdouble-promotion.
HUGE_VAL is the double-precision infinity constant.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Allocate as hb_gpu_texel_t* directly instead of char* to avoid
an alignment-increasing cast.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The demo requires GLEW, GLFW3, and GL. Make these optional so the
library still builds on headless systems. The demo is skipped when
they're missing.
Install the GL packages in the Linux CI workflow so the demo
builds there.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The object is a draw_funcs_t closure, same role as hb_raster_draw_t.
Rename for consistency with the other modules.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move the executable definition to util/meson.build so the binary
lands at util/hb-gpu, consistent with other utilities.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_object_destroy() already calls obj->~Type() for non-trivially-
destructible types, which runs hb_vector_t's destructor. The
explicit curves.fini() was freeing the array a second time.
Also remove encode_buf reuse — allocate fresh each encode call
and let the blob own the buffer via its destroy callback.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fall back to an embedded font when no font file is given,
matching the glyphy-demo behaviour.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the glyphy-demo to use the hb-gpu API. Builds as util/hb-gpu
and requires GLEW, GLFW3, and OpenGL 3.3. Includes default text
and embedded font for quick testing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port the glyphy library into harfbuzz as a new hb-gpu module,
following the hb-raster / hb-vector library pattern. The module
encodes glyph outlines into compact RGBA16I blobs for GPU rendering
using the Slug algorithm.
Fixes https://github.com/harfbuzz/harfbuzz/issues/5877
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Also simplify clear() itself to just call shrink_vector(0) directly,
avoiding the resize() -> alloc() path which both fails in error state
and requires Type to be default-constructible.
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The raster SVG image callback assumes hb_raster_paint_glyph()
seeded svg_font/svg_glyph state before the paint protocol
reaches HB_PAINT_IMAGE_FORMAT_SVG. Clients can also call
hb_font_paint_glyph_or_fail() directly with
hb_raster_paint_get_funcs(), which leaves svg_font unset and
crashes in hb_raster_svg_render().
Return false when the callback is reached without that
wrapper-only state, and cover the direct API path with a
regression test.
Testing: CCACHE_DISABLE=1 meson test -C build
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-ggh9-cgg2-r4vr
Assisted-by: OpenAI Codex <codex@openai.com>
The previous fix (d134f888) zeroed `length` but skipped element
destructors. Call shrink_vector(0) instead, which properly destructs
items before clearing length.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cursive attachment reversal clears the old child edge before
walking the existing chain and reinstalling reversed links.
If the chain distance does not stay in range for
attach_chain(), reinstalling the reversed edge can truncate
and leave a poisoned chain value.
Pass the buffer length into the reversal helper so it drops
out-of-bounds chains, and use a round-trip fit check before
storing the reversed distance. When the reversed distance does
not fit, leave the old edge detached instead of corrupting
the chain.
Testing: CCACHE_DISABLE=1 meson test -C build --print-errorlogs
Fixes https://issues.chromium.org/issues/496302307
Assisted-by: OpenAI Codex <codex@openai.com>
Reject simple glyf data that claims fewer points than contours.
Such data cannot describe a valid outline, so fail before
allocating and decoding contour points.
Testing: CCACHE_DISABLE=1 meson test -C b
Assisted-by: OpenAI Codex <codex@openai.com>
clear() called resize(0) which calls alloc(0), but alloc() bails
immediately when the vector is in error state, so length was never
zeroed. Under failing-malloc, a vector could enter error state from
a failed push, making all subsequent clear() calls silently fail,
leaving stale pointers.
This caused a heap-use-after-free in hb_raster_paint_destroy():
render() released surfaces to surface_cache then called
surface_stack.clear() which silently failed, so destroy() iterated
the stale surface_stack pointers and double-freed images already
in surface_cache.
Fixes https://oss-fuzz.com/testcase?key=5078588000108544
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_raster_png_error() switched to png_longjmp() when raster PNG
error handling was hardened. That symbol is only available with
newer libpng headers, but HarfBuzz does not require a minimum
libpng version.
Follow cairo-png.c and jump through png_jmpbuf() instead. This
keeps the error path working with older libpng headers, including
macOS framework builds that pick up pre-1.5 libpng.
Testing:
meson test -C build
Fixes: https://github.com/harfbuzz/harfbuzz/issues/5867
Assisted-by: OpenAI Codex
* [docs] Note failing-malloc in fuzzing guidance
Document that HarfBuzz fuzzers run with failing-malloc enabled so
out-of-memory handling remains part of the expected exercised
surface during fuzzing work.
Testing: not run (documentation-only change)
Assisted-by: OpenAI Codex
* Add a fuzzer font
* [vector] Fail closed on SVG paint body OOM
The SVG paint backend could keep going after failing-malloc
poisoned the root or nested group body buffers. In particular,
hb_vector_paint_ensure_initialized() only checked group_stack
itself, not the allocated root body, and some group and glyph
paths ignored push_or_fail() or append-induced vector error
state.
Treat an errored root body as initialization failure, reject
cached and non-cached glyph emission when defs, current body,
or captured scratch enter error state, and stop ignoring
nested group push failure.
Testing: CCACHE_DISABLE=1 meson test -C build-codex
Fixes: https://oss-fuzz.com/testcase-detail/4521131913838592
Assisted-by: OpenAI Codex
* [vector] Reject errored SVG paint bodies
Under failing-malloc, the SVG paint backend could leave the
root body or captured glyph body vector in an error state and
then keep appending to it. Group initialization only checked
group_stack itself, not the nested root body, and glyph
emission reported success even when defs, current body, or
captured scratch had entered vector error state.
Treat an errored root body as init failure, reject cached and
non-cached glyph emission once those vectors enter error, and
stop ignoring push_or_fail() in push_group().
Testing: CCACHE_DISABLE=1 meson test -C build-codex
Fixes: https://oss-fuzz.com/testcase-detail/4521131913838592
Assisted-by: OpenAI Codex
Under failing-malloc, the SVG paint backend could leave the
root body or captured glyph body vector in an error state and
then keep appending to it. Group initialization only checked
group_stack itself, not the nested root body, and glyph
emission reported success even when defs, current body, or
captured scratch had entered vector error state.
Treat an errored root body as init failure, reject cached and
non-cached glyph emission once those vectors enter error, and
stop ignoring push_or_fail() in push_group().
Testing: CCACHE_DISABLE=1 meson test -C build-codex
Fixes: https://oss-fuzz.com/testcase-detail/4521131913838592
Assisted-by: OpenAI Codex
The SVG paint backend could keep going after failing-malloc
poisoned the root or nested group body buffers. In particular,
hb_vector_paint_ensure_initialized() only checked group_stack
itself, not the allocated root body, and some group and glyph
paths ignored push_or_fail() or append-induced vector error
state.
Treat an errored root body as initialization failure, reject
cached and non-cached glyph emission when defs, current body,
or captured scratch enter error state, and stop ignoring
nested group push failure.
Testing: CCACHE_DISABLE=1 meson test -C build-codex
Fixes: https://oss-fuzz.com/testcase-detail/4521131913838592
Assisted-by: OpenAI Codex
Document that HarfBuzz fuzzers run with failing-malloc enabled so
out-of-memory handling remains part of the expected exercised
surface during fuzzing work.
Testing: not run (documentation-only change)
Assisted-by: OpenAI Codex