From c22ae24405e86957b355d7d3bb1dda70fd0ff65c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 7 Oct 2026 12:06:58 -0600 Subject: [PATCH] [set] Reject unequal populations when comparing mixed inversion (#6329) The mixed-inversion equality path compares zipped iterators, which stop at the shorter set. An empty set therefore compares equal to a full inverted set, as does any matching finite prefix. Check populations before comparing members and add regression coverage for empty sets and matching prefixes in both argument orders. Validation: meson test -C build (261 passed, 1 skipped). Assisted-by: OpenAI Codex --- src/hb-bit-set-invertible.hh | 3 +++ test/api/test-set.c | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/hb-bit-set-invertible.hh b/src/hb-bit-set-invertible.hh index 089c73c2c..5d61adc35 100644 --- a/src/hb-bit-set-invertible.hh +++ b/src/hb-bit-set-invertible.hh @@ -191,6 +191,9 @@ struct hb_bit_set_invertible_t return s.is_equal (other.s); else { + if (get_population () != other.get_population ()) + return false; + /* TODO Add iter_ranges() and use here. */ auto it1 = iter (); auto it2 = other.iter (); diff --git a/test/api/test-set.c b/test/api/test-set.c index 295e17580..3f29f1d4d 100644 --- a/test/api/test-set.c +++ b/test/api/test-set.c @@ -1024,6 +1024,31 @@ test_set_inverted_equality (void) hb_set_destroy (b); } +static void +test_set_mixed_inversion_equality (void) +{ + hb_set_t *a = hb_set_create (); + hb_set_t *b = hb_set_create (); + hb_set_invert (b); + + /* Empty and full sets have the same (empty) zipped prefix. */ + g_assert_false (hb_set_is_equal (a, b)); + g_assert_false (hb_set_is_equal (b, a)); + + /* Matching initial members do not imply equal sets. */ + hb_set_add_range (a, 0, 10); + g_assert_false (hb_set_is_equal (a, b)); + g_assert_false (hb_set_is_equal (b, a)); + + hb_set_del_range (b, 0, 4); + hb_set_del_range (a, 0, 4); + g_assert_false (hb_set_is_equal (a, b)); + g_assert_false (hb_set_is_equal (b, a)); + + hb_set_destroy (a); + hb_set_destroy (b); +} + static void test_set_intersects (void) { @@ -1438,6 +1463,7 @@ main (int argc, char **argv) hb_test_add (test_set_inverted_iteration_next); hb_test_add (test_set_inverted_iteration_prev); hb_test_add (test_set_inverted_equality); + hb_test_add (test_set_mixed_inversion_equality); hb_test_add (test_set_intersects); hb_test_add (test_set_inverted_operations);