Commit Graph
199 Commits
Author SHA1 Message Date
jfkthame 603ab95602 Return size_t rather than unsigned int from get_size() (#5915)
* [subset] Return size_t rather than unsigned from get_size() methods

It's possible some get_size() computations during serialization
may overflow 32-bit arithmetic.

(The result of get_size() is used as size_t when allocating via
hb_serialize_context_t::extend(), but if the return value was
declared as unsigned int, the value may have wrapped resulting
in under-allocation.)

* [subset] Use size_t when accumulating subset_data_size

* [graph] Use size_t (rather than signed int64_t) for vertex_len variables

* Use size_t for sanitize_closure_t::stride to avoid narrowing
2026-04-13 11:01:19 -06:00
Qunxin Liu 380ae0122f [subset-repack] dont duplicate node that might be shared (#5889)
repacker will duplicate it if actually needed
2026-04-11 22:23:40 -06:00
Kyr1o5anddefault f099a260d9 Fix: Add safety limits to hb-repacker to prevent algorithmic complexity attacks (#5904)
* Fix: Algorithmic Complexity DoS in HarfBuzz Repacker

Introduce total iteration limits in overflow resolution loop and physical growth limits (vertices and spaces) to prevent Hang/OOM during subsetting of malicious fonts.

* Repacker: Move safety limits to hb-limits.hh as requested by Behdad

---------

Co-authored-by: default <default@zimbra.0day.lab>
2026-04-10 18:06:24 -06:00
Qunxin Liu e601560b77 fix fuzzer issue: https://oss-fuzz.com/testcase-detail/6005602106277888
Do not use pointers that may point outside of the allocated memory region
2026-01-23 11:44:39 -07:00
Qunxin Liu b17fa8ef39 Fix fuzzer found heap-use-after-free crash (#5717)
Fixes https://oss-fuzz.com/testcase-detail/6005602106277888
2026-01-21 14:42:29 -07:00
Qunxin Liu babdb46be3 [repacker] bug fix for splitting shared subtables (#5686)
And fix splitting for ligatureSubst table with shared coverage table
2025-12-19 21:42:20 -07:00
Garret Rieger 09c14fa4f2 Fix fuzzer found memory leak. (#5643)
Fixes https://oss-fuzz.com/testcase-detail/6083012753424384
2025-11-14 02:27:35 -07:00
Behdad Esfahbod 346b8dcf93 Wrap formats in struct
Part of https://github.com/harfbuzz/harfbuzz/issues/5601

This was done automatically using codex, the ChatGPT coding
agent.
2025-11-11 12:29:06 -07:00
Behdad Esfahbod 2bcce37ffd [Coverage] Wrap format in a struct
Part of https://github.com/harfbuzz/harfbuzz/issues/5601
2025-11-11 02:24:50 -07:00
Qunxin Liu cb6e12bf3e [repacker] remap 24 bits links cause they could be roots (#5631) 2025-11-01 16:39:29 -06:00
Garret Rieger 07ee609f5a Fix invalid pointer conversions in graph Coverage. (#5622)
For #5604.
2025-10-20 20:06:43 -06:00
Qunxin Liu fdb80534e2 [subset-repacker] bug fix: copy markFilteringSet field if exists (#5579) 2025-09-23 15:32:41 -06:00
Garret Rieger 54ab8f0df4 [repacker] make repacker object ids stable.
Prior to this change the object id for a vertex in the repacker graph is it's position in the topological ordering. As a result after each sorting the object ids change. This decouples the topological sorting from the object id assignments. A separate ordering list is retained. This simplifies handling around object ids which no longer needs to account for them shifting, and improves performance by eliminating the step of reassigned link object ids after each sort.
2025-09-15 16:34:44 -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 2dc0b070e8 [test] Mark a couple functions as unused
Under NDEBUG.
2025-07-25 02:28:44 -06:00
Garret Rieger 8c79e4f8a0 [repacker] Add batch version of move_child().
Move child is O(n) where n = number of links on the parent object. The batch version is also O(n). Use this in ligature splitting clone range to avoid O(n^2) behaviour.
2025-07-23 16:46:36 -06:00
Garret Rieger 38181c3fbf [repacker] cache liga index to object id maps between clone_range calls. 2025-07-23 16:46:36 -06:00
Garret Rieger 1caab75bfd [repacker] fix O(n^2) behaviour in LigatureSubstFormat1::clone_range. 2025-07-23 16:46:36 -06:00
Garret Rieger ee4a7a3208 [repacker] fix O(n^2) in LigatureSubstFormat1::shrink. 2025-07-23 16:46:36 -06:00
Garret Rieger 870b37bab6 [repacker] optimize ligature splitting implementation.
Eliminate O(n^2) behaviour in compute_split_points().
2025-07-23 16:46:36 -06:00
Garret Rieger 2dfaf2a22e [repacker] fix imports. 2025-07-10 16:11:15 +00:00
Garret Rieger e50d16f6f8 [repacker] During liga splitting re-use orphaned liga sets. 2025-07-10 00:58:49 +00:00
Garret Rieger cad418860a [repacker] fix bug where nodes with incoming virtual links could get orphaned.
When attempting to fix overflows nodes that have incoming edges from more than one parent can be duplicated. However, if all of these incoming links are virtual except for one duplicating it will effectively orphan it (one of the copies will be pointed to only by virtual links). Since parent book keeping is expensive we don't want to separately track virtual/real parents so instead just don't duplicate nodes that have at least one incoming virtual link.
2025-07-09 17:09:05 +00:00
Garret Rieger 18c67b7789 [repacker] store liga counts before processing.
Otherwise processing changes the counts when we need them later on.
2025-07-08 22:40:18 +00:00
Garret Rieger 4fa5788cfd [repacker] fix bug with original count in liga splitting. 2025-07-08 21:29:48 +00:00
Garret Rieger 96fedd88fe [repacker] Fix handling of virtual links in liga table splitting. 2025-07-08 20:36:13 +00:00
Garret Rieger 5b47710f56 [repacker] Start implementing test for liga splitting. 2025-07-07 20:15:30 +00:00
Garret Rieger 38ab13c67e [repacker] add support for splitting GSUB Ligature lookups. 2025-07-04 23:37:24 +00:00
Ebrahim Byagowi 677d6646a1 [subset] Make sure the clamp is done in a int64_t space
Otherwise nags about things like this,

In member function ‘int64_t graph::graph_t::vertex_t::modified_distance(unsigned int) const’,
    inlined from ‘void graph::graph_t::sort_shortest_distance()’ at ../src/graph/graph.hh:626:24:
../src/graph/graph.hh:371:20: warning: dangling pointer to an unnamed temporary may be used [-Wdangling-pointer=]
  371 |           hb_clamp (distance + distance_modifier (), (uint64_t) 0, (uint64_t) 0x7FFFFFFFFFF);
      |           ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And some of the CI bots fail also like this https://github.com/harfbuzz/harfbuzz/actions/runs/9838686960/job/27159310858?pr=4793

But it probably something else also can be improved which maybe is out of scope for this particular change.
2024-07-08 11:06:53 -06:00
Ebrahim Byagowi 495937f96d [subset] Use hb_clamp instead of consequent hb_min and hb_max calls
As just a minor code tweak to clarify the intention better.
2024-07-08 11:06:53 -06:00
Garret Rieger 79eaa217ac [repacker] remove unused include. 2024-03-14 21:22:22 +00:00
Garret Rieger 025f52769f [repacker] fix mem leak in test-classdef-graph test. 2024-03-09 00:32:36 +00:00
Garret Rieger 8e1beefe05 [repacker] small fixes. 2024-03-08 22:05:20 +00:00
Garret Rieger 17b37f10d5 [repacker] add classdef size est. test that you can add the same class multiple times. 2024-03-08 22:01:05 +00:00
Garret Rieger 0ac9e7da39 [repacker] in classdef estimator tests compare results to actual class def serialization.
Fix the estimator to actually match real serialization sizes.
2024-03-08 21:53:10 +00:00
Garret Rieger 8129b21dea Update classdef size estimator to pick the min coverage format.
Previously this just assumed a worst case format 1.
2024-03-08 20:15:43 +00:00
Garret Rieger 252a926fbf [repacker] Rework how ClassDef sizes are estimated during splitting.
The old approach considered only one class at a time, which in some cases can generate the wrong answer. This change updates the estimation to consider how all classes in the current split would end up encoded in a single ClassDef table. Additionally compute whether glyphs are consecutive only for the current split (instead of the fully mapping).
2024-03-08 19:46:48 +00:00
Garret Rieger 7160c5b9e5 [repacker] add tests for multi-duplication.
Further improve the resolution attempt by pre-emptively raising priority of a duplicated shared node.
2023-12-05 16:25:12 -05:00
Garret Rieger 6f64fa75e3 [repacker] improve resolution of overflows to shared nodes.
Prior to this change overflows to shared nodes were handled by duplicating the link from only a single parent on each iteration. However, I've encountered fonts where there is a large number of parents sharing a single child. Using the prior strategy requires large number of overflow resolution iterations to resolve overflows. This changes shared overflow resolution to duplicate the shared child and re-assign multiple overflowing parents in a single iteration. This reduces total packing size in these cases and allows resolution to complete in far fewer iterations.
2023-12-05 16:25:12 -05:00
Behdad Esfahbod 330c32f902 [graph] Another preallocation 2023-11-10 12:27:48 -07:00
Behdad Esfahbod 9c4d3c3c70 [graph] Pre-alloc priority-heap array 2023-11-10 12:26:02 -07:00
Behdad Esfahbod 3a9262cc3d [sanitize] More hb_barrier() annotations 2023-11-04 15:21:47 -06:00
Garret Rieger 52bc78e70d s/PairPos/MarkBasePos/ in MarkBasePos repacking implementation. 2023-10-16 12:25:25 -06:00
Qunxin Liu 1f395cbaf9 [instancer] templatize the priority queue, use custom type for varstore
when instantiating varstore, we need to pop a tuple like
(combined_gain, i, j), if combined gain is the same then we compare the
value of i, and then j. So we'd like to use custom type as the key when
popping from the queue. This would match fonttool's algorithm cause it
uses heappop().
2023-10-13 14:52:27 -06:00
Vincent Torri 17ee3cd7f4 fix warning with unsigned long 2023-09-10 11:34:30 +03:00
Garret Rieger a1f034eaac [repacker] fix fuzzer failure.
Fixes: https://oss-fuzz.com/testcase-detail/6490945267564544
2023-08-28 23:17:13 -04:00
Garret Rieger c28fdc39b2 [repacker] fix bot failure. 2023-08-23 17:03:54 -06:00
Garret Rieger 5587247d5b [repacker] create only one extension subtable per physical subtable.
During extension promotion when multiple lookups refer to a shared subtable node create and reuse a single extension subtable for it. Fixes: https://github.com/fonttools/fonttools/issues/3260.
2023-08-23 17:03:54 -06:00
Garret Rieger ca906e8747 [repacker] fix fuzzer timeout.
Corrects some mistakes in the handling of incoming_edges_ when memory allocation failures happen.
2023-08-17 12:01:44 -06:00
Behdad Esfahbod 91c449a64a [graph] Make space_for non-recursive
It was tail-recursive so perhaps the compiler did the same.
Anyway, make it explicit now.
2023-08-02 14:40:55 -06:00