hb_hashmap_t::update() iterates other's items array while inserting
each pair into *this with set(). When other is *this and occupancy
sits on a growth threshold (5 of 8, 10 of 16, ...), the first set()
calls alloc(), which frees the items array the iterator is still
walking, so the rest of the loop reads freed memory. The existing
in_storage() guard only protects set()'s own key/value references,
not this iterator.
Merging a map into itself cannot change it, so make update() a no-op
in that case with an early &other == this return, mirroring the
self-check in hb_vector_t. hb_map_update() is the only caller.
Regression tests are added in src/test-map.cc (including the tombstone
case at 42 used / 10 live slots) and test/api/test-map.c; both fail
under ASan without the fix.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-7TMM2Z2T.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
m.set (99, m.get (1)) passes a reference into the map's own items
array. If the insertion needs to grow the table, alloc() frees that
array before the value is read, so set_with_hash() copies from freed
memory. Same for the key, eg. m.set (m.get (1), v).
When growth is needed and the key or value lies within our storage,
copy them out first and insert the copies. The copies are
default-constructed and then assigned, matching how items are filled,
since some key types (eg. OT::OffsetTo) are not copy-constructible.
Added test-map cases for value and key aliasing, including a
non-trivial value type. Reproduced with ASan before the fix; test-map
is clean under ASan+UBSan after it, and meson test passes.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- Limit max population size of map to prevent size from overflowing.
- Fix possibly overflow population * 8
- Correctly handle copying a map that's in error.
This reverts commit f657ef7e57.
This breaks many compilers with messages like this:
hb-subset-plan.hh:226: undefined reference to `OT::head::tableTag'
I'm out of my depth re how to fix it.
Dereferencing them is not supported anymore after
3aad7c2ddf
We don't support that for regular pointers, so don't supporting
them for smart-pointers sounds right to me.