@@ -478,6 +478,61 @@ TEST_F(FontHelperTest, BuildFont) {
478478 ASSERT_EQ (table_2.str (), " table_2" );
479479}
480480
481+ TEST_F (FontHelperTest, GlyfData_ShortOverflow) {
482+ // This glyph has a start < 65536 and end > 65536 and so will create an
483+ // overflow in offset calculation if the wrong data types are used.
484+ auto data = FontHelper::GlyfData (roboto_vf.get (), 558 );
485+ ASSERT_TRUE (data.ok ()) << data.status ();
486+ ASSERT_GT (data->size (), 0 );
487+ }
488+
489+ TEST_F (FontHelperTest, GlyfData_ShortOverflowSynthetic) {
490+ hb_face_unique_ptr face = make_hb_face (hb_face_builder_create ());
491+
492+ std::vector<uint8_t > loca = {
493+ 0xC3 , 0x50 , // 50,000 (100,000 actual)
494+ 0xC3 , 0x52 , // 50,002 (100,005 actual)
495+ };
496+ {
497+ auto blob =
498+ make_hb_blob (hb_blob_create ((const char *)loca.data (), loca.size (),
499+ HB_MEMORY_MODE_READONLY, nullptr , nullptr ));
500+ hb_face_builder_add_table (face.get (), HB_TAG (' l' , ' o' , ' c' , ' a' ),
501+ blob.get ());
502+ }
503+
504+ std::vector<uint8_t > head (53 , 0 );
505+ head[51 ] = 0 ;
506+ {
507+ auto blob =
508+ make_hb_blob (hb_blob_create ((const char *)head.data (), head.size (),
509+ HB_MEMORY_MODE_READONLY, nullptr , nullptr ));
510+ hb_face_builder_add_table (face.get (), HB_TAG (' h' , ' e' , ' a' , ' d' ),
511+ blob.get ());
512+ }
513+
514+ std::vector<uint8_t > glyf (100004 , 0 );
515+ glyf[100000 ] = 1 ;
516+ glyf[100001 ] = 2 ;
517+ glyf[100002 ] = 3 ;
518+ glyf[100003 ] = 4 ;
519+ {
520+ auto blob =
521+ make_hb_blob (hb_blob_create ((const char *)glyf.data (), glyf.size (),
522+ HB_MEMORY_MODE_READONLY, nullptr , nullptr ));
523+ hb_face_builder_add_table (face.get (), HB_TAG (' g' , ' l' , ' y' , ' f' ),
524+ blob.get ());
525+ }
526+
527+ auto blob = make_hb_blob (hb_face_reference_blob (face.get ()));
528+ auto concrete_face = make_hb_face (hb_face_create (blob.get (), 0 ));
529+
530+ auto data = FontHelper::GlyfData (concrete_face.get (), 0 );
531+ ASSERT_TRUE (data.ok ()) << data.status ();
532+ std::string expected = {1 , 2 , 3 , 4 };
533+ ASSERT_EQ (*data, expected);
534+ }
535+
481536// TODO test BuildFont...
482537
483538} // namespace common
0 commit comments