mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
[subset] Compute COLR constant_after_pinning once per plan
PaintRadialGradient::constant_after_pinning() answers a question about the source ItemVariationStore and the subset plan only, yet it rescanned every variation region (building a hashmap per region, up to 32767) on every paint visit. Shared paints are visited once per reference by OffsetTo::serialize_subset(), so during partial instancing the cost grew as visits x regionCount: 40 s to 6 minutes for a 192 KB font with a PaintComposite chain and many regions. Cache the answer in a tri-state plan field (-1 until computed, like the lazily-set has_gdef_varstore flag) so the scan runs at most once per plan; the plan is valid for one source face and one set of axis locations, so this is sound. Move the cheap varIdxBase != NO_VARIATION test ahead of the scan so non-variable format 6 gradients never trigger it. The allocation-failure path of get_var_region() still sets the serializer error and returns uncached, as before. Output is byte-identical; the attack font drops from ~41 s to ~0.03 s. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-910I4C0Y. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
f2b79d995c
commit
5b319d5bfc
3 files changed
+11
-4
No files matched your search
@@ -890,6 +890,10 @@ struct PaintRadialGradient
|
||||
const ItemVarStoreInstancer &instancer) const
|
||||
{
|
||||
if (c->plan->has_avar2) return false;
|
||||
/* The answer depends on the table and the plan only, but shared paints
|
||||
* are visited once per reference, so compute it once per plan. */
|
||||
int &constant = c->plan->colrv1_constant_after_pinning;
|
||||
if (constant >= 0) return constant;
|
||||
const auto ®ions = instancer.varStore->get_region_list ();
|
||||
for (unsigned i = 0; i < regions.regionCount; i++)
|
||||
{
|
||||
@@ -904,10 +908,10 @@ struct PaintRadialGradient
|
||||
Triple *limit;
|
||||
if (!c->plan->user_axes_location.has (axis.first, &limit) ||
|
||||
limit->minimum != limit->maximum)
|
||||
return false;
|
||||
return (constant = false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return (constant = true);
|
||||
}
|
||||
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const {}
|
||||
@@ -1052,9 +1056,8 @@ struct PaintRadialGradient
|
||||
uint32_t varIdxBase) const
|
||||
{
|
||||
TRACE_SUBSET (this);
|
||||
if (instancer && !c->plan->pinned_at_default &&
|
||||
if (instancer && !c->plan->pinned_at_default && varIdxBase != VarIdx::NO_VARIATION &&
|
||||
(c->plan->all_axes_pinned || constant_after_pinning (c, instancer)) &&
|
||||
varIdxBase != VarIdx::NO_VARIATION &&
|
||||
(radius0 + (double) roundf (instancer (varIdxBase, 2)) < 0 ||
|
||||
radius1 + (double) roundf (instancer (varIdxBase, 5)) < 0))
|
||||
return_trace (subset_nonnegative (c, instancer, varIdxBase));
|
||||
|
||||
@@ -695,6 +695,7 @@ hb_subset_plan_t::hb_subset_plan_t (hb_face_t *face,
|
||||
all_axes_pinned = false;
|
||||
pinned_at_default = true;
|
||||
has_gdef_varstore = false;
|
||||
colrv1_constant_after_pinning = -1;
|
||||
has_avar2 = false;
|
||||
|
||||
#ifdef HB_EXPERIMENTAL_API
|
||||
|
||||
@@ -169,6 +169,9 @@ struct hb_subset_plan_t
|
||||
// whether GDEF ItemVariationStore is retained
|
||||
mutable bool has_gdef_varstore;
|
||||
|
||||
// whether every COLR variation region uses pinned axes only; -1 until computed
|
||||
int colrv1_constant_after_pinning;
|
||||
|
||||
// whether we're doing avar2 partial instancing
|
||||
bool has_avar2;
|
||||
|
||||
|
||||
Reference in new issue
Block a user