mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 23:41:03 +01:00
[subset] Charge layout glyph walks to the existing subset budget
Drop the separate HB_BUDGET_SUBSET_TABLE budget and the second hb_subset_context_t field it needed; check_ops() now charges budget_remaining (HB_BUDGET_SUBSET_GLYF, 1 << 28), the per-table budget glyf instancing already uses. Both are per-table and shared across buffer-size retries, and no table spends both. The larger budget still bounds the attack (fails after 2^28 glyph steps, ~3 s), so test_subset_shared_coverage_budget now expects the failure at 8192 shared offsets instead of 2048. Subsetting all glyphs with --layout-features='*' of Gulzar, NotoSansKR-VF and GoogleSansFlex-VF keeps GSUB/GPOS/GDEF with output byte-identical to before; the heaviest table (Gulzar GPOS) spends ~98K units, under 0.04% of the budget. Full meson test: 278 OK. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c5b920a0f9
commit
1af279ed98
3 files changed
+11
-16
No files matched your search
+4
-9
@@ -243,7 +243,10 @@ hb_budget_spend (int64_t &budget, unsigned int cost, unsigned int mult = 1)
|
||||
* variable fonts spend -- the largest glyf variable font under test/
|
||||
* (MPLUS1-Variable, 6,434 glyphs retained) uses ~1.2M units, and even a
|
||||
* font at the 65,535-glyph maximum stays far below -- while keeping the
|
||||
* adversarial worst case bounded. */
|
||||
* adversarial worst case bounded. Layout tables charge their Coverage
|
||||
* and ClassDef glyph walks to the same budget: a glyph range costs a few
|
||||
* bytes and any number of offsets can share it, so neither the table size
|
||||
* nor the sanitizer's budget bounds that work. */
|
||||
#ifndef HB_BUDGET_SUBSET_GLYF
|
||||
#define HB_BUDGET_SUBSET_GLYF ((int64_t) 1 << 28)
|
||||
#endif
|
||||
@@ -276,14 +279,6 @@ hb_budget_spend (int64_t &budget, unsigned int cost, unsigned int mult = 1)
|
||||
#define HB_BUDGET_AAT_MAP ((int64_t) 1 << 24)
|
||||
#endif
|
||||
|
||||
/* Subsetting one table, in glyphs visited while walking its Coverage and
|
||||
* ClassDef tables. A glyph range costs a few bytes and any number of
|
||||
* offsets can share it, so neither the table size nor the sanitizer's
|
||||
* budget bounds that work. */
|
||||
#ifndef HB_BUDGET_SUBSET_TABLE
|
||||
#define HB_BUDGET_SUBSET_TABLE ((int64_t) 1 << 26)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HB_REPACKER_MAX_ITERATIONS
|
||||
#define HB_REPACKER_MAX_ITERATIONS 500
|
||||
|
||||
+4
-4
@@ -58,16 +58,16 @@ struct hb_subset_context_t :
|
||||
/* Charge COUNT units of work that the size of the source table does
|
||||
* not bound. Fails the table once its budget is exhausted. */
|
||||
bool check_ops (unsigned count)
|
||||
{ return serializer->check_success (hb_budget_spend (budget, count)); }
|
||||
{ return serializer->check_success (hb_budget_spend (budget_remaining, count)); }
|
||||
|
||||
hb_blob_t *source_blob;
|
||||
hb_subset_plan_t *plan;
|
||||
hb_serialize_context_t *serializer;
|
||||
hb_tag_t table_tag;
|
||||
/* Outline work left for instancing this table. Lives here rather than in
|
||||
* the table's subset() so retries with a larger buffer share it. */
|
||||
/* Work left for subsetting this table: outline work for glyf instancing,
|
||||
* Coverage and ClassDef glyph walks for layout tables. Lives here rather
|
||||
* than in the table's subset() so retries with a larger buffer share it. */
|
||||
int64_t budget_remaining = HB_BUDGET_SUBSET_GLYF;
|
||||
int64_t budget = HB_BUDGET_SUBSET_TABLE;
|
||||
|
||||
hb_subset_context_t (hb_blob_t *source_blob_,
|
||||
hb_subset_plan_t *plan_,
|
||||
|
||||
@@ -161,11 +161,11 @@ static void
|
||||
test_subset_shared_coverage_budget (void)
|
||||
{
|
||||
/* Walking 65535 glyphs per offset must run out of the per-table work
|
||||
* budget (HB_BUDGET_SUBSET_TABLE) at 2048 offsets, but not at 256. */
|
||||
* budget (HB_BUDGET_SUBSET_GLYF) at 8192 offsets, but not at 256. */
|
||||
static const struct { unsigned backtrack_count, range_last; hb_bool_t expected; } cases[] = {
|
||||
{ 2048, 1, TRUE },
|
||||
{ 8192, 1, TRUE },
|
||||
{ 256, 65534, TRUE },
|
||||
{ 2048, 65534, FALSE },
|
||||
{ 8192, 65534, FALSE },
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < G_N_ELEMENTS (cases); i++)
|
||||
|
||||
Reference in new issue
Block a user