[cff] Reject INDEX item counts that do not fit (#6465)

CFF1 INDEX counts are 16-bit. Serializing a larger iterator truncated
its count before reserving the offset array, then wrote offsets for
every item. Check the count before allocating or writing the offsets.

Test the CFF1 boundary and the corresponding valid CFF2 counts, and
reject a subset glyph mapping that overflows the CharStrings INDEX.
Both regressions fail before this change. The full Meson suite passes
(293 tests), including the subset and API suites.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-8ROS1VQ9.

Assisted-by: OpenAI Codex
This commit is contained in:
Behdad Esfahbod authored and GitHub committed 2026-10-29 18:31:46 -06:00
1 parent cd4d7664e1
commit 1e6a7f38ee
3 files changed
+42 -1

No files matched your search

+2 -1
View File
@@ -1322,7 +1322,8 @@ struct CFFIndex
/* serialize CFFIndex header */
if (unlikely (!c->extend_min (this))) return_trace (false);
this->count = hb_len (it);
if (unlikely (!c->check_assign (this->count, hb_len (it), HB_SERIALIZE_ERROR_ARRAY_OVERFLOW)))
return_trace (false);
if (!this->count) return_trace (true);
if (unlikely (!c->extend (this->offSize))) return_trace (false);
this->offSize = off_size;
+24
View File
@@ -155,9 +155,33 @@ test_fd_select_sentinel ()
c.end_processing ();
}
static void
test_index_count_limits ()
{
char buffer[65550];
for (unsigned count : {0u, 65535u, 65536u, 65537u})
{
auto items = hb_range (count) | hb_map ([] (unsigned) { return hb_bytes_t (); });
hb_serialize_context_t c (buffer, sizeof (buffer));
auto *index = c.start_serialize<OT::CFF1Index> ();
bool success = index->serialize_header (&c, +items, 0);
hb_always_assert (success == (count <= 65535u));
if (success)
hb_always_assert (index->count == count);
else
hb_always_assert (c.in_error ());
hb_serialize_context_t c2 (buffer, sizeof (buffer));
auto *index2 = c2.start_serialize<OT::CFF2Index> ();
hb_always_assert (index2->serialize_header (&c2, +items, 0));
hb_always_assert (index2->count == count);
}
}
int
main (int argc, char **argv)
{
test_index_count_limits ();
test_specialized_line_geometry ();
test_specialized_fractional_geometry ();
test_charset1_splits_long_ranges ();
+16
View File
@@ -520,10 +520,26 @@ test_subset_cff1_caller_supplied_subr (void)
hb_face_destroy (face);
}
static void
test_subset_cff1_index_count_overflow (void)
{
hb_face_t *face = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,4C2E.otf");
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
hb_set_add (hb_subset_input_glyph_set (input), 1);
/* The output CharStrings count must fit in a CFF1 INDEX. */
hb_map_set (hb_subset_input_old_to_new_glyph_mapping (input), 1, 70000);
g_assert_null (hb_subset_or_fail (face, input));
hb_subset_input_destroy (input);
hb_face_destroy (face);
}
int
main (int argc, char **argv)
{
hb_test_init (&argc, &argv);
hb_test_add (test_subset_cff1_index_count_overflow);
hb_test_add (test_subset_cff1_caller_supplied_subr);