mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-29 17:44:06 +01:00
[depend] Release oversized recursion maps in reset_recurse_cache()
reset_recurse_cache() runs once per top-level lookup and cleared completed_recursions and recurse_path_to_index with hb_hashmap_t::clear(), which walks the whole table and keeps its allocated capacity. A single lookup that grew these maps large therefore made every later top-level lookup pay to walk that full capacity, however little it recursed, giving a font with one busy lookup followed by many trivial ones a CPU DoS in hb_subset_depend_from_face_or_fail(). Add clear_or_release(): when a map is large but was left mostly empty by the lookup that just finished, swap in fresh storage before clearing, so later lookups start from a small table. Adds a fuzzer regression font. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-PNJPHF76. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
d6d66b9422
commit
06e9e32980
2 files changed
+14
-2
No files matched your search
@@ -670,10 +670,22 @@ struct hb_depend_context_t :
|
||||
void finish_recurse (const recurse_key_t &key)
|
||||
{ depend_data->check_success (completed_recursions.set (key, true)); }
|
||||
|
||||
/* hb_hashmap_t::clear() walks the whole table and keeps its storage.
|
||||
* Keep the storage only if the lookup that just finished made use of it.
|
||||
* Otherwise one lookup that grew the table would make every later lookup
|
||||
* pay for its full capacity, however little that lookup recursed. */
|
||||
template <typename Map>
|
||||
static void clear_or_release (Map &map)
|
||||
{
|
||||
if (map.size () > 64 && map.get_population () < map.size () / 8)
|
||||
map = Map (); /* Swaps in fresh storage; a no-op in error state. */
|
||||
map.clear ();
|
||||
}
|
||||
|
||||
void reset_recurse_cache ()
|
||||
{
|
||||
completed_recursions.clear ();
|
||||
recurse_path_to_index.clear ();
|
||||
clear_or_release (completed_recursions);
|
||||
clear_or_release (recurse_path_to_index);
|
||||
recurse_path = 0;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user