[ot-font] Handle scratch alloc failures

Might fix https://issues.oss-fuzz.com/issues/433311403
This commit is contained in:
Behdad Esfahbod committed 2025-07-21 22:49:11 -06:00
1 parent 03387e3fde
commit c0052d1753
2 files changed
+19 -4

No files matched your search

+4 -4
View File
@@ -445,8 +445,7 @@ struct glyf_accelerator_t
if (coords)
{
hb_glyf_scratch_t *scratch = acquire_scratch ();
if (unlikely (!scratch))
return false;
if (unlikely (!scratch)) return false;
bool ret = get_points (font,
gid,
points_aggregator_t (font, extents, nullptr, true),
@@ -493,8 +492,7 @@ struct glyf_accelerator_t
if (!has_data ()) return false;
hb_glyf_scratch_t *scratch = acquire_scratch ();
if (unlikely (!scratch))
return true;
if (unlikely (!scratch)) return true;
bool ret = get_points (font, gid, glyf_impl::path_builder_t (font, draw_session),
hb_array (font->coords,
@@ -534,6 +532,8 @@ struct glyf_accelerator_t
}
void release_scratch (hb_glyf_scratch_t *scratch) const
{
if (!scratch)
return;
if (!cached_scratch.cmpexch (nullptr, scratch))
{
scratch->~hb_glyf_scratch_t ();
+15
View File
@@ -466,6 +466,11 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data,
{
const auto &glyf = *ot_face->glyf;
auto *scratch = glyf.acquire_scratch ();
if (unlikely (!scratch))
{
ot_font->h.release_advance_cache (advance_cache);
goto fallback;
}
OT::hb_scalar_cache_t *gvar_cache = ot_font->draw.acquire_gvar_cache (gvar);
for (unsigned int i = 0; i < count; i++)
@@ -587,6 +592,11 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data,
{
const auto &glyf = *ot_face->glyf;
auto *scratch = glyf.acquire_scratch ();
if (unlikely (!scratch))
{
ot_font->v.release_advance_cache (advance_cache);
goto fallback;
}
OT::hb_scalar_cache_t *gvar_cache = ot_font->draw.acquire_gvar_cache (gvar);
for (unsigned int i = 0; i < count; i++)
@@ -718,6 +728,11 @@ hb_ot_get_glyph_v_origins (hb_font_t *font,
if (origin_cache && vmtx.has_data() && glyf.has_data ())
{
auto *scratch = glyf.acquire_scratch ();
if (unlikely (!scratch))
{
ot_font->v_origin.release_origin_cache (origin_cache);
return false;
}
OT::hb_scalar_cache_t *gvar_cache = font->has_nonzero_coords ?
ot_font->draw.acquire_gvar_cache (*ot_face->gvar) :
nullptr;