* [build] Avoid libstdc++ assertions in unoptimized builds
Recent libstdc++ headers enable assertions at -O0. Atomic operations
then reference std::__glibcxx_assert_fail, which is unavailable when
HarfBuzz uses the C linker without libstdc++.
Define _GLIBCXX_NO_ASSERTIONS in Meson and CMake builds. Undefine
_GLIBCXX_ASSERTIONS in Meson as well, since Meson enables it for debug
builds.
Verified Clang 21.1.8 with libstdc++ 15.3.1 debug shared-library builds
in both build systems, using --no-undefined with CMake. Confirmed that
harfbuzz and harfbuzz-gpu have no assertion reference or libstdc++
dependency. The full Meson suite passed: 295 tests, one skipped.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6528
Assisted-by: Codex
* [build] Configure libstdc++ assertions in hb.hh
Move the assertion settings from Meson and CMake to the internal header
so custom builds and amalgamations also avoid the runtime dependency.
The settings must precede the first C++ standard header. hb-atomic.hh
is included after other standard headers, so set them at the top of
hb.hh instead.
Verified Clang debug shared-library builds with Meson and CMake, plus a
direct -O0 build of harfbuzz.cc with pthread mutexes and assertions
explicitly enabled on the command line. All link without libstdc++ and
have no assertion reference. The GCC atomic repro also passes. The full
Meson suite passed: 295 tests, one skipped.
Assisted-by: Codex
* [test] Keep vector string operations instrumented under MSan
Including hb.hh first disables libstdc++ assertions and restores its
extern template declarations for std::string. The vector test then
calls the uninstrumented copy constructor from libstdc++, and MSan
reports uninitialized state when moving the temporary copy.
Include string before hb.hh so the test retains the inline string
implementations that MSan can instrument.
Reproduced with Clang 18 and libstdc++ 14 using CI's assertion flags.
The original test fails and the updated test passes under MSan. The
full regular Meson suite passed: 295 tests, one skipped.
Assisted-by: Codex
hb_alloc_pool_t::alloc(0) legitimately returns nullptr while no shared
chunk is open, but hb_vector_t::allocate_from_pool() took any nullptr as
an allocation failure and flagged the (empty) vector with set_error().
The next allocate_from_pool() on it then tripped
assert(!length && !allocated), aborting hb-subset during partial
instancing of a crafted ~1 KB variable font whose retained glyph has
more than 16,376 points (so no small request ever opens the shared
chunk) and whose tuple is split by the requested axis range.
Fix the root cause where the vector already special-cases zero-size
requests on the heap path: a null result is a failure only when bytes
were requested (size && !arrayZ).
tuple_delta_t::copy_from() also discarded the results of its seven
duplicate_vector_from_pool() calls, so a genuine pool failure during a
tuple clone would reach the same assert (or silently drop gvar under
NDEBUG); it now returns bool, change_tuple_var_axis_limit() marks out in
error, and change_tuple_variations_axis_limits() fails instead of
continuing.
A regression test for the zero-size pool allocation is added to
src/test-vector.cc. The attack font now instances to the same output as
the control; test-vector and the subset suite pass.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-N0R68QRI.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reject allocation requests above INT_MAX before growing the capacity,
and cap geometric growth at that limit. Otherwise the unsigned growth
loop can wrap, or a successful allocation can store a negative value
in the signed capacity field. Normalize exact requests before checking
the limit so the existing length is included.
Test both normal and exact oversized requests, preservation of existing
contents on failure, and saturation of geometric growth. Intercept the
allocator in the unit test to avoid allocating large buffers. The new
regression fails before the fix. All 293 tests pass, and test-vector
passes under ASan and UBSan.
Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-N6HMDRS8.
Assisted-by: OpenAI Codex
push (v[i]) reads its argument after alloc() may have moved the
vector's backing storage. Array extension has the same problem.
This is reachable through item_variations_t::duplicate_row() when
subsetting avar2 axes that share a variation row.
Construct a temporary before growth when a push argument aliases our
storage, and recover aliased source arrays by offset after allocation.
Keep the alias check on the push growth path, and reject already-failed
vectors before moving from their arguments.
Share the array extension implementation and route direct vector
extension through it, making v.extend (v) safe as well. General iterator
adapters into the same vector still cannot survive reallocation.
Add regressions for trivial and non-trivial copies, aliased moves,
constructor arguments, mutable and const arrays, direct self-extension,
and already-failed vectors. Reproduced push and both extension failures
under ASan before the fix. The updated tests pass under ASan+UBSan and
GCC with HB_TINY; injected allocation failures are clean under the
sanitizers. The full Meson suite passes (292 passed, 1 skipped).
Assisted-by: Claude
Assisted-by: Codex
Co-authored-by: Mar <mardgez13@gmail.com>
Copy assignment resets the destination before reading the source. When
they are the same vector, this also clears the source. In particular,
hb_set_set(set, set) loses the set's stored pages.
Return immediately for self assignment. Cover trivial and nontrivial
vector elements and public set assignment in both inversion modes.
Validation: both regressions fail before the fix; meson test -C build
passes (261 passed, 1 skipped).
Assisted-by: OpenAI Codex