mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-12-01 10:34:23 +01:00
[subset] Keep ClassDef range traversal in sync for class zero (#6473)
The class-zero intersection loop skipped ranges starting at glyph 0 without advancing the last glyph, and consulted a separate iterator instead of the range being visited. Probe only actual gaps and always advance past each range, so unlisted glyphs retain class-zero rules. Check all 256 glyph sets over eight glyphs against per-glyph class lookup for empty, contiguous, gapped, and explicit class-zero ranges. The regression fails on the old source. The full Meson suite passes (293 tests), including shape and subset. Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-K9HEP9ZU. Assisted-by: OpenAI Codex
This commit is contained in:
1 parent
90045a6551
commit
ecf0bc81aa
2 files changed
+47
-12
No files matched your search
@@ -327,9 +327,47 @@ static void test_running_class_size_estimates_with_locally_consecutive_glyphs ()
|
||||
hb_always_assert(check_add_class_def_size(estimator, map, 3, {2, 3}));
|
||||
}
|
||||
|
||||
static void
|
||||
test_class_def_intersects_class ()
|
||||
{
|
||||
/* Range count, then first/last/class for each range. Include gaps,
|
||||
* adjacent ranges, explicit class zero, and ranges starting at gid 0. */
|
||||
const unsigned cases[][7] = {
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
{1, 0, 3, 1, 0, 0, 0},
|
||||
{1, 0, 7, 1, 0, 0, 0},
|
||||
{2, 0, 1, 1, 4, 5, 2},
|
||||
{2, 0, 1, 1, 2, 3, 2},
|
||||
{2, 0, 1, 0, 4, 5, 2},
|
||||
{2, 1, 2, 1, 4, 5, 2},
|
||||
};
|
||||
for (const auto &ranges : cases)
|
||||
{
|
||||
OT::HBUINT16 data[8];
|
||||
data[0] = 2;
|
||||
for (unsigned i = 0; i < 7; i++)
|
||||
data[i + 1] = ranges[i];
|
||||
const auto &class_def = *reinterpret_cast<const OT::ClassDef *> (data);
|
||||
for (unsigned mask = 0; mask < 256; mask++)
|
||||
{
|
||||
hb_set_t glyphs;
|
||||
for (unsigned g = 0; g < 8; g++)
|
||||
if (mask & (1u << g)) glyphs.add (g);
|
||||
for (unsigned klass = 0; klass < 4; klass++)
|
||||
{
|
||||
bool expected = false;
|
||||
for (auto g : glyphs)
|
||||
expected |= class_def.get_class (g) == klass;
|
||||
hb_always_assert (class_def.intersects_class (&glyphs, klass) == expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
test_class_def_intersects_class ();
|
||||
test_class_and_coverage_size_estimates ();
|
||||
test_running_class_and_coverage_size_estimates ();
|
||||
test_running_class_size_estimates_with_locally_consecutive_glyphs ();
|
||||
|
||||
@@ -1972,21 +1972,18 @@ struct ClassDefFormat2_4
|
||||
/* Match if there's any glyph that is not listed! */
|
||||
hb_codepoint_t g = HB_SET_VALUE_INVALID;
|
||||
hb_codepoint_t last = HB_SET_VALUE_INVALID;
|
||||
auto it = hb_iter (rangeRecord);
|
||||
for (auto &range : it)
|
||||
for (auto &range : rangeRecord)
|
||||
{
|
||||
if (it->first == last + 1)
|
||||
/* Only probe for a glyph in the gap before this range; a range
|
||||
* starting right after the previous one (or at glyph 0) has none. */
|
||||
if (range.first != last + 1)
|
||||
{
|
||||
it++;
|
||||
continue;
|
||||
if (!glyphs->next (&g))
|
||||
break;
|
||||
if (g < range.first)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!glyphs->next (&g))
|
||||
break;
|
||||
if (g < range.first)
|
||||
return true;
|
||||
g = range.last;
|
||||
last = g;
|
||||
g = last = range.last;
|
||||
}
|
||||
if (g != HB_SET_VALUE_INVALID && glyphs->next (&g))
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user