Commit Graph
21 Commits
Author SHA1 Message Date
Behdad Esfahbod e8a578bf07 [build] Avoid libstdc++ assertions in unoptimized builds (#6534)
* [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
2026-10-31 20:10:00 -06:00
Behdad EsfahbodandClaude Opus 4.8 d73f4eea07 [instancer] Treat a zero-size pool allocation as success in gvar instancing
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>
2026-10-30 14:53:31 -06:00
Behdad Esfahbod 8f115ee233 [vector] Keep allocation capacity representable as an int (#6484)
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
2026-10-29 20:58:54 -06:00
Behdad EsfahbodandMar 9df939b153 [vector] Fix use-after-free when appending from own storage (#6393)
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>
2026-10-13 16:32:31 -06:00
Behdad Esfahbod 0529c75459 [vector] Preserve contents on self-copy assignment (#6331)
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
2026-10-07 12:16:05 -06:00
Behdad Esfahbod 75f919876f [src/test-*] Use hb_always_assert() which isn't compiled out under NDEBUG
Part of https://github.com/harfbuzz/harfbuzz/issues/5418
2025-07-25 03:00:38 -06:00
Behdad Esfahbod 5872bdf64d [vector] Add copy-constructor for array_t's 2023-05-26 11:44:18 -06:00
Behdad Esfahbod 915c1a00cf [vector] Add remove_unordered
Saves 5% in NotoNastaliq/1000 subset benchmark.
2022-11-26 14:48:57 -07:00
Behdad Esfahbod 039e476bac [test-vector] Test sink-move'ing 2022-11-18 19:26:02 -07:00
Behdad Esfahbod 1bf9afaad0 [test-vector] Test sink interface 2022-11-18 18:20:50 -07:00
Behdad Esfahbod 557be9502a [test-vector] Fix test 2022-11-16 12:47:05 -07:00
Behdad Esfahbod f734c26c5c [test-vector] Test inserting set and map 2022-11-15 16:27:56 -07:00
Behdad Esfahbod 85e0be1357 [vector/array] Add simple test for sorted size 2022-11-13 17:28:09 -07:00
Behdad Esfahbod 3bd755c32d [test-vector] Test remove()
Currently buggy. Valgrind confirms.
2022-05-19 15:51:18 -06:00
Behdad Esfahbod 37d3275dec [test-vector] Enable disabled test
This seems to work already.
2022-05-19 15:43:15 -06:00
Behdad Esfahbod e61234c5f7 [vector] Add tests for move constructor/assignment 2022-05-12 13:20:10 -06:00
Behdad Esfahbod 63affc4eae [vector] Move semantics when resizing 2022-01-15 12:24:20 -08:00
Behdad Esfahbod c30f6834d0 [map] Add 5 methods 2021-11-01 22:29:14 -06:00
Behdad Esfahbod 6f74d80ed1 [vector] Complete sorted_vector 5-methods 2021-11-01 21:49:32 -06:00
Behdad Esfahbod 628a0f3796 [vector] Add more tests 2021-11-01 20:36:55 -06:00
Behdad Esfahbod 11135150a7 [vector] Move test code into separate file 2021-11-01 20:23:12 -06:00