mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
[graphite2] Initialize mask of glyphs the shaper adds
_hb_graphite2_shape() grows buffer->info with ensure() (a plain realloc) and then fills each output glyph field by field, but never assigned hb_glyph_info_t::mask. Entries beyond the original text length therefore kept uninitialised heap bytes (or, in a reused buffer, the mask from a previous shaping run); clear_glyph_flags() only rewrites the low three bits, so hb_buffer_get_glyph_infos() handed the stale bits 3-31 to the caller. Shaping output is correct (every in-tree reader masks down to HB_GLYPH_FLAG_DEFINED), but valgrind/MSan flag the uninitialised bytes and code reading the private field sees values that vary run to run. Set info->mask = 0 in the fill loop, next to the other fields. That matches what hb_buffer_t::add() starts from and what the OpenType shaper returns after hb_propagate_flags(), so the subsequent clear_glyph_flags()/unsafe_to_break() operate on a defined value and shaping output is unchanged. No other shaper needs the change. Adds test_graphite2_inserted_glyph_masks, which first runs the OpenType shaper so a removed default-ignorable leaves a non-zero mask in the buffer storage, then checks that every glyph the Graphite shaper adds for U+0622 comes back with nothing but glyph-flag bits. Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-UDVJURW0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
e8f8ee612f
commit
b32bfc243d
2 files changed
+48
No files matched your search
@@ -416,6 +416,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
|
||||
{
|
||||
hb_glyph_info_t *info = &buffer->info[clusters[i].base_glyph + j];
|
||||
info->codepoint = glyphs[clusters[i].base_glyph + j].codepoint;
|
||||
info->mask = 0;
|
||||
info->cluster = HB_BUFFER_CLUSTER_LEVEL_IS_MONOTONE (buffer->cluster_level) ?
|
||||
glyphs[clusters[i].base_glyph + j].cluster :
|
||||
clusters[i].cluster;
|
||||
|
||||
@@ -66,12 +66,59 @@ test_graphite2_repeated_clusters (void)
|
||||
hb_font_destroy (font);
|
||||
}
|
||||
|
||||
static void
|
||||
test_graphite2_inserted_glyph_masks (void)
|
||||
{
|
||||
const char *ot_shapers[] = {"ot", NULL};
|
||||
const char *graphite2_shapers[] = {"graphite2", NULL};
|
||||
hb_face_t *face;
|
||||
hb_font_t *font;
|
||||
hb_buffer_t *buffer;
|
||||
hb_glyph_info_t *info;
|
||||
unsigned int length;
|
||||
|
||||
face = hb_test_open_font_file ("../subset/data/fonts/Harmattan-Regular.ttf");
|
||||
font = hb_font_create (face);
|
||||
hb_face_destroy (face);
|
||||
|
||||
buffer = hb_buffer_create ();
|
||||
|
||||
/* Leave stale masks in the buffer storage beyond its length: the OpenType
|
||||
* shaper sets every mask during shaping and only cleans the glyphs that
|
||||
* survive, so a removed default-ignorable leaves its mask behind. */
|
||||
hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_UNICODE);
|
||||
hb_buffer_set_flags (buffer, HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES);
|
||||
hb_buffer_add (buffer, 0x0628, 0);
|
||||
hb_buffer_add (buffer, 0x200B, 1);
|
||||
hb_buffer_guess_segment_properties (buffer);
|
||||
g_assert_true (hb_shape_full (font, buffer, NULL, 0, ot_shapers));
|
||||
info = hb_buffer_get_glyph_infos (buffer, &length);
|
||||
g_assert_cmpuint (length, ==, 1);
|
||||
|
||||
/* Now let Graphite produce more glyphs than there were characters; the
|
||||
* added glyphs must come back with nothing but glyph flags in their mask. */
|
||||
hb_buffer_clear_contents (buffer);
|
||||
hb_buffer_set_content_type (buffer, HB_BUFFER_CONTENT_TYPE_UNICODE);
|
||||
hb_buffer_set_flags (buffer, HB_BUFFER_FLAG_DEFAULT);
|
||||
hb_buffer_add (buffer, 0x0622, 0);
|
||||
hb_buffer_guess_segment_properties (buffer);
|
||||
g_assert_true (hb_shape_full (font, buffer, NULL, 0, graphite2_shapers));
|
||||
info = hb_buffer_get_glyph_infos (buffer, &length);
|
||||
g_assert_cmpuint (length, ==, 2);
|
||||
for (unsigned int i = 0; i < length; i++)
|
||||
g_assert_cmphex (info[i].mask & ~HB_GLYPH_FLAG_DEFINED, ==, 0);
|
||||
|
||||
hb_buffer_destroy (buffer);
|
||||
hb_font_destroy (font);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
hb_test_init (&argc, &argv);
|
||||
|
||||
hb_test_add (test_graphite2_repeated_clusters);
|
||||
hb_test_add (test_graphite2_inserted_glyph_masks);
|
||||
|
||||
return hb_test_run ();
|
||||
}
|
||||
Reference in new issue
Block a user