9 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.8 2f8fb68973 [map] Fix use-after-free when updating a map from itself
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>
2026-10-30 16:35:27 -06:00
parasol-aserandjeffhuang da577bc545 test: strengthen buffer and map API coverage (#5979)
Add focused API tests for hb_buffer_create_similar() and buffer
configuration persistence across clear/reset. Also exercise public hb_map
copy, equality, hash, update, iteration, keys, and values paths with
order-independent assertions.

Validation:
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer
meson test -C build-tgl-precheck --print-errorlogs --suite api test-map
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer test-map

Assisted-by: OpenAI Codex <codex@openai.com>

Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>
2026-05-06 17:27:10 -06:00
Behdad Esfahbod 155e1e633b [test/api] Use g_assert_true instead of g_assert
The latter terminates the program. The former marks the test
as failing.
2025-04-06 03:49:15 -06:00
Garret Rieger c08f1b8903 [map] fix incorrect population count in hash map.
If the same key was set twice the population was being incorrectly incremented.
2021-08-10 14:00:55 -06:00
Chun-wei Fan 1e09add232 test/api: Fix building on pre-C99 compilers
Ensure variables are declared at the top of the block.
2018-12-12 01:32:01 +08:00
Behdad Esfahbod 4e09fb8f7a Oops. Fix build 2018-10-19 19:59:41 -07:00
Behdad Esfahbod 9e288d29d8 [test-map] Cosmetic 2018-10-19 19:47:27 -07:00
Ebrahim Byagowi 114f66dda6 Fix hb_map_is_empty logic
This needs reviewing
2018-10-19 20:23:36 +03:30
Ebrahim Byagowi 9df2fb1611 Add API tests for hb_map_t 2018-10-19 20:23:36 +03:30