Coverage Report

Created: 2026-12-01 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/hb-limits.hh
Line
Count
Source
1
/*
2
 * Copyright © 2022  Behdad Esfahbod
3
 *
4
 *  This is part of HarfBuzz, a text shaping library.
5
 *
6
 * Permission is hereby granted, without written agreement and without
7
 * license or royalty fees, to use, copy, modify, and distribute this
8
 * software and its documentation for any purpose, provided that the
9
 * above copyright notice and the following two paragraphs appear in
10
 * all copies of this software.
11
 *
12
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16
 * DAMAGE.
17
 *
18
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23
 */
24
25
#ifndef HB_LIMITS_HH
26
#define HB_LIMITS_HH
27
28
#include "hb.hh"
29
30
31
#ifndef HB_BUFFER_MAX_LEN_FACTOR
32
#define HB_BUFFER_MAX_LEN_FACTOR 512
33
#endif
34
#ifndef HB_BUFFER_MAX_LEN_MIN
35
2.42M
#define HB_BUFFER_MAX_LEN_MIN 65536
36
#endif
37
#ifndef HB_BUFFER_MAX_LEN_DEFAULT
38
2.42M
#define HB_BUFFER_MAX_LEN_DEFAULT 0x3FFFFFFF /* Shaping more than a billion chars? Let us know! */
39
#endif
40
41
#ifndef HB_BUFFER_MAX_OPS_FACTOR
42
/* Duployan fonts spend up to ~4.3K operations per input character on
43
 * words and sentences.  Allow over ten times that. */
44
2.42M
#define HB_BUFFER_MAX_OPS_FACTOR 65536
45
#endif
46
#ifndef HB_BUFFER_MAX_OPS_MIN
47
/* Short Duployan inputs spend up to ~37K operations before the linear
48
 * allowance takes over. */
49
2.42M
#define HB_BUFFER_MAX_OPS_MIN 524288
50
#endif
51
#ifndef HB_BUFFER_MAX_OPS_DEFAULT
52
4.84M
#define HB_BUFFER_MAX_OPS_DEFAULT 0x3FFFFFFF /* Shaping more than a billion operations? Let us know! */
53
#endif
54
55
56
#ifndef HB_MAX_NESTING_LEVEL
57
0
#define HB_MAX_NESTING_LEVEL 64
58
#endif
59
60
61
#ifndef HB_MAX_CONTEXT_LENGTH
62
0
#define HB_MAX_CONTEXT_LENGTH 64
63
#endif
64
65
#ifndef HB_MAX_SYLLABLE_LENGTH
66
664k
#define HB_MAX_SYLLABLE_LENGTH 64
67
#endif
68
69
#ifndef HB_CLOSURE_MAX_STAGES
70
/*
71
 * The maximum number of times a lookup can be applied during shaping.
72
 * Used to limit the number of iterations of the closure algorithm.
73
 * This must be larger than the number of times add_gsub_pause() is
74
 * called in a collect_features call of any shaper.
75
 */
76
0
#define HB_CLOSURE_MAX_STAGES 16
77
#endif
78
79
#ifndef HB_MAX_SCRIPTS
80
0
#define HB_MAX_SCRIPTS 500
81
#endif
82
83
#ifndef HB_MAX_LANGSYS
84
0
#define HB_MAX_LANGSYS 2000
85
#endif
86
87
#ifndef HB_MAX_LANGSYS_FEATURE_COUNT
88
#define HB_MAX_LANGSYS_FEATURE_COUNT 50000
89
#endif
90
91
#ifndef HB_MAX_FEATURE_INDICES
92
0
#define HB_MAX_FEATURE_INDICES 8000
93
#endif
94
95
#ifndef HB_MAX_LOOKUP_VISIT_COUNT
96
0
#define HB_MAX_LOOKUP_VISIT_COUNT 35000
97
#endif
98
99
/* Distinct lookup recursion paths the dependency graph builder interns
100
 * over a whole GSUB; building the graph fails when it needs more.
101
 * Lookups that invoke each other in every order make a factorial number
102
 * of them.  The most among the test fonts is 744 (NotoNastaliqUrdu-Bold). */
103
#ifndef HB_MAX_DEPEND_RECURSE_PATHS
104
#define HB_MAX_DEPEND_RECURSE_PATHS 35000
105
#endif
106
107
/* Subtables of one kern, kerx, mort, or morx table; the table is rejected
108
 * when it declares more.  The table's accelerator keeps glyph sets for
109
 * each, which can take far more memory than the subtable has bytes. */
110
#ifndef HB_AAT_MAX_SUBTABLES
111
#define HB_AAT_MAX_SUBTABLES 1024
112
#endif
113
114
#ifndef HB_MAX_GRAPH_EDGE_COUNT
115
0
#define HB_MAX_GRAPH_EDGE_COUNT 16384
116
#endif
117
118
/* Maximum number of edges stored in one glyph dependency graph.  GSUB
119
 * edges are keyed by (source, target, feature tag), so a lookup reached
120
 * by many feature tags multiplies its substitutions by the tag count and
121
 * a small table can describe a graph of hundreds of millions of edges. */
122
#ifndef HB_DEPEND_MAX_EDGES
123
#define HB_DEPEND_MAX_EDGES (1u << 25)
124
#endif
125
126
#ifndef HB_VAR_COMPOSITE_MAX_AXES
127
0
#define HB_VAR_COMPOSITE_MAX_AXES 4096
128
#endif
129
130
/* Region axes copied into tuples when one ItemVariationStore is converted
131
 * for instancing, summed over its VarData subtables.  Every region a
132
 * VarData references gets its own copy of that region's axes, and the
133
 * font pays a few bytes per reference however many axes the region has. */
134
#ifndef HB_VARSTORE_MAX_TUPLE_AXES
135
#define HB_VARSTORE_MAX_TUPLE_AXES (1u << 20)
136
#endif
137
138
/* Deltas that instancing an avar version 2 table may add to its variation
139
 * store as offset-compensation tuples.  Each tuple holds a delta for every
140
 * row of the VarData it is added to, but the breakpoint it encodes costs
141
 * four bytes of the table and a VarData without regions stores its rows in
142
 * no bytes at all, so the table size does not bound that memory.  The
143
 * budget is this many deltas per byte of the table, but no less than the
144
 * minimum; exceeding it fails the table. */
145
#ifndef HB_AVAR2_MAX_DELTAS_FACTOR
146
#define HB_AVAR2_MAX_DELTAS_FACTOR 128
147
#endif
148
#ifndef HB_AVAR2_MAX_DELTAS_MIN
149
#define HB_AVAR2_MAX_DELTAS_MIN 65536
150
#endif
151
152
#ifndef HB_GLYF_MAX_POINTS
153
0
#define HB_GLYF_MAX_POINTS 200000
154
#endif
155
156
#ifndef HB_CFF_MAX_OPS
157
0
#define HB_CFF_MAX_OPS 200000
158
#endif
159
160
/* Private DICT operators that the accelerator of one CFF or CFF2 table
161
 * records for the subsetter.  Any number of Font DICTs can name the same
162
 * Private DICT, so the size of the table does not bound them.  The limit
163
 * is one operator per byte of the table, which a table whose Font DICTs
164
 * do not share their Private DICTs cannot exceed, but no less than this
165
 * minimum; exceeding it fails the table. */
166
#ifndef HB_CFF_MAX_PRIVATE_DICT_OPS_MIN
167
#define HB_CFF_MAX_PRIVATE_DICT_OPS_MIN 16384
168
#endif
169
170
#ifndef HB_MAX_COMPOSITE_OPERATIONS_PER_GLYPH
171
#define HB_MAX_COMPOSITE_OPERATIONS_PER_GLYPH 64
172
#endif
173
174
/* Maximum serialized subset table size, as a multiple of the source table
175
 * length, with a floor for compact tables that expand under renumbering.
176
 * The serializer's INT_MAX allocation ceiling still applies. */
177
#ifndef HB_SUBSET_MAX_TABLE_SIZE_FACTOR
178
#define HB_SUBSET_MAX_TABLE_SIZE_FACTOR 256
179
#endif
180
#ifndef HB_SUBSET_MAX_TABLE_SIZE_MIN
181
#define HB_SUBSET_MAX_TABLE_SIZE_MIN ((uint64_t) 1 << 20)
182
#endif
183
184
/* Source bytes of all the glyphs the subsetter retains, as a multiple of
185
 * the glyf table length; exceeding it fails the plan.  A monotonic loca
186
 * never needs more than one; a loca that aliases the same bytes to many
187
 * glyph IDs makes trimming and hint dropping cost that many table scans. */
188
#ifndef HB_SUBSET_GLYF_MAX_BYTES_FACTOR
189
#define HB_SUBSET_GLYF_MAX_BYTES_FACTOR 16
190
#endif
191
192
#ifndef HB_GPU_DRAW_MAX_CURVES
193
#define HB_GPU_DRAW_MAX_CURVES 65536
194
#endif
195
196
/* Bytes the CBDT subsetter may copy out of the source CBDT table, as a
197
 * multiple of that table's length.  Image blocks of different glyphs or
198
 * strikes may overlap or repeat, so bounds-checking each block against the
199
 * table does not bound their sum. */
200
#ifndef HB_SUBSET_CBDT_MAX_COPY_FACTOR
201
#define HB_SUBSET_CBDT_MAX_COPY_FACTOR 64
202
#endif
203
204
/* Strikes of a CBLC table considered when choosing one for a glyph query;
205
 * later ones are ignored.  numSizes is a 32-bit field and every query walks
206
 * the strikes, while ppem is 8-bit and real fonts have a handful. */
207
#ifndef HB_CBLC_MAX_STRIKES
208
0
#define HB_CBLC_MAX_STRIKES 256
209
#endif
210
211
/* Total bytes of sub-blobs (gradient color stops, clip outlines) in one
212
 * hb_gpu_paint_t walk; exceeding it makes the paint unsupported. */
213
#ifndef HB_GPU_PAINT_MAX_SUB_BYTES
214
#define HB_GPU_PAINT_MAX_SUB_BYTES ((unsigned) 64 << 20)
215
#endif
216
217
/* Tiles emitted by one hb_paint_sweep_gradient_tiles() call.  Also
218
 * sets the angular resolution (2π over this) below which a repeating
219
 * color line is filled with its average color instead of tiled;
220
 * a repeat/reflect color line whose stops span a tiny angle could
221
 * otherwise emit millions of patches while covering 0..2π. */
222
#ifndef HB_PAINT_MAX_SWEEP_TILES
223
0
#define HB_PAINT_MAX_SWEEP_TILES 4096
224
#endif
225
226
#ifndef HB_SVG_MAX_DOCUMENT_SIZE
227
#define HB_SVG_MAX_DOCUMENT_SIZE ((size_t) 16 << 20)
228
#endif
229
230
/* Maximum size of one serialized vector document (SVG or PDF) produced by
231
 * the vector backends.  Bounds output that is not outline-derived -- most
232
 * of a path, but especially sweep-gradient meshes and embedded bitmaps --
233
 * which the outline work budget cannot see.  Unsigned (not size_t like the
234
 * SVG-table limit above) to match hb_vector_buf_t's unsigned length arithmetic. */
235
#ifndef HB_VECTOR_MAX_DOCUMENT_SIZE
236
#define HB_VECTOR_MAX_DOCUMENT_SIZE ((unsigned) 40 << 20)
237
#endif
238
239
#ifndef HB_RASTER_MAX_BUFFER_SIZE
240
#define HB_RASTER_MAX_BUFFER_SIZE ((size_t) 1 << 30)
241
#endif
242
243
/* Combined backing storage of a paint context's group surfaces and clip
244
 * masks, including caches. A larger explicit root surface can stand alone. */
245
#ifndef HB_RASTER_MAX_PAINT_STORAGE
246
#define HB_RASTER_MAX_PAINT_STORAGE ((uint64_t) 256 << 20)
247
#endif
248
249
/* Maximum surface dimension (pixels per side) when extents are derived
250
 * from font data (glyph extents, accumulated outline bounds, or the header
251
 * of an embedded PNG image about to be decoded).  Bounds
252
 * attacker-controlled allocations; extents set explicitly through
253
 * hb_raster_{draw,paint}_set_extents() are not limited. */
254
#ifndef HB_RASTER_MAX_AUTO_DIMENSION
255
#define HB_RASTER_MAX_AUTO_DIMENSION 4096
256
#endif
257
258
/*
259
 * Cumulative work budgets.
260
 *
261
 * The limits above bound work within one subsystem: points per glyf
262
 * glyph, ops per CFF charstring, nodes in a COLR or VARC graph,
263
 * pixels per raster surface.  When one subsystem drives another --
264
 * COLR driving a paint backend, a paint backend or VARC loading
265
 * glyf/CFF outlines -- those limits multiply.  Each driving session
266
 * therefore carries one cumulative budget, initialized once per
267
 * top-level entry and only ever decremented, shared by everything
268
 * the session consumes.  Once a budget is exhausted, further work
269
 * is skipped best-effort.
270
 */
271
272
/* Fixed relative weights.  Keep the value in the name so charge sites are
273
 * easy to audit; tune the common session cap, not these values. */
274
0
#define HB_BUDGET_1 1u
275
#define HB_BUDGET_2 2u
276
#define HB_BUDGET_4 4u
277
#define HB_BUDGET_8 8u
278
0
#define HB_BUDGET_16  16u
279
#define HB_BUDGET_32  32u
280
#define HB_BUDGET_64  64u
281
#define HB_BUDGET_128 128u
282
#define HB_BUDGET_256 256u
283
#define HB_BUDGET_512 512u
284
#define HB_BUDGET_1024  1024u
285
286
/* The common finite default for one top-level glyph rendering session.
287
 * Nested outline and paint work shares the same live counter.  The
288
 * heaviest glyphs measured, those of Bitcount Ink over its design
289
 * space, spend 2 million; this is eight times that. */
290
#ifndef HB_BUDGET_GLYPH
291
0
#define HB_BUDGET_GLYPH ((int64_t) 1 << 24)
292
#endif
293
294
/* Precharge COST * MULT.  Callers bound COST and MULT structurally, and live
295
 * budgets are concrete non-negative values when a session starts. */
296
static HB_ALWAYS_INLINE bool
297
hb_budget_spend (int64_t &budget, unsigned int cost, unsigned int mult = 1)
298
0
{
299
0
  budget -= (int64_t) cost * mult;
300
0
  return budget >= 0;
301
0
}
Unexecuted instantiation: hb-blob.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-buffer.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-common.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-face.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-face-builder.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-fallback-shape.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-font.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-number.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-face.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-font.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-outline.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: VARC.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-metrics.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shape.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-var.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-set.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-shape-plan.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-shaper.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-static.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-unicode.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ft.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-aat-layout.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-aat-map.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-draw.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-paint.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-paint-bounded.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-paint-extents.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-cff1-table.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-cff2-table.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-layout.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-map.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-arabic.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-default.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-hangul.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-hebrew.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-indic.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-khmer.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-myanmar.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-syllabic.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-thai.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-use.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-vowel-constraints.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shape-fallback.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shape-normalize.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-tag.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ucd.cc:hb_budget_spend(long&, unsigned int, unsigned int)
Unexecuted instantiation: hb-ot-shaper-indic-table.cc:hb_budget_spend(long&, unsigned int, unsigned int)
302
303
/* One glyf instancing session in the subsetter.  It loads the outline of
304
 * every retained glyph, and composite components are loaded again for each
305
 * glyph that uses them, so the per-glyph budget (HB_BUDGET_GLYPH) would
306
 * multiply by the glyph count.  This is one cumulative budget for the whole
307
 * table instead; exhausting it fails the table.  Sized well above what real
308
 * variable fonts spend -- instancing all 1,605 glyphs of Handjet at the
309
 * midpoint of its axes uses ~625M units -- while keeping the
310
 * adversarial worst case bounded. */
311
#ifndef HB_BUDGET_SUBSET_GLYF
312
#define HB_BUDGET_SUBSET_GLYF ((int64_t) 1 << 33)
313
#endif
314
315
/* Coverage and ClassDef glyph walks while subsetting one layout table, or
316
 * while collecting the layout variation indices of one subset plan.
317
 * A glyph range costs a few bytes and any number of offsets can share it,
318
 * so neither the table size nor the sanitizer's budget bounds that work. */
319
#ifndef HB_BUDGET_SUBSET_LAYOUT
320
0
#define HB_BUDGET_SUBSET_LAYOUT ((int64_t) 1 << 28)
321
#endif
322
323
/* The flat floor for the subsetter's work on the charstrings of a CFF or
324
 * CFF2 table, in operators and operands interpreted, shared by all passes
325
 * of one subset over them.  Glyphs can share subroutines, so neither
326
 * HB_CFF_MAX_OPS per glyph nor the table size bounds that work.  Running
327
 * out fails the charstring being interpreted, as exceeding HB_CFF_MAX_OPS
328
 * does. */
329
#ifndef HB_BUDGET_SUBSET_CFF
330
#define HB_BUDGET_SUBSET_CFF ((int64_t) 1 << 25)
331
#endif
332
333
/* Very large CFF and CFF2 tables still get several operations per byte;
334
 * subroutinized fonts interpret a few operations per table byte. */
335
#ifndef HB_BUDGET_SUBSET_CFF_PER_BYTE
336
#define HB_BUDGET_SUBSET_CFF_PER_BYTE 96
337
#endif
338
339
/* Partially instancing one CFF2 table in the subsetter, in cells of the
340
 * old-region to new-region matrices built for its VarDatas.  A VarData
341
 * with k regions costs k * k cells for 2 * k bytes of font, and many
342
 * offsets can share one VarData.  Exceeding the budget fails the table. */
343
#ifndef HB_BUDGET_SUBSET_CFF2_CELLS
344
#define HB_BUDGET_SUBSET_CFF2_CELLS ((int64_t) 1 << 24)
345
#endif
346
347
/* The flat pixel-work floor for one raster draw or paint session.  Pixel and
348
 * outline work use separate live counters, so keep this independent of
349
 * the common outline budget above.
350
 *
351
 * Small surfaces live off this.  What a layer of a color paint costs does
352
 * not shrink as fast as the area of the surface does, so the smaller the
353
 * surface, the more times its area a glyph needs: Bitcount Ink with every
354
 * axis at its maximum needs 680 times at 64 pixels per em, 3 million in
355
 * all, and 18 million at 256. */
356
#ifndef HB_BUDGET_RASTER_PIXELS
357
#define HB_BUDGET_RASTER_PIXELS ((int64_t) 1 << 26)
358
#endif
359
360
/* Larger paint surfaces get pixel work in proportion to their area.  A
361
 * layer is charged for its mask, its clip and its fill, over the box it
362
 * can show in.  The most that takes at 2048 pixels per em is 122 times
363
 * the area of the surface, for Bitcount Ink with every axis at its
364
 * maximum; allow four times that.  Its default instance needs 18 times,
365
 * and the heaviest glyph of Noto Color Emoji 110. */
366
#ifndef HB_BUDGET_RASTER_PAINT_PASSES
367
#define HB_BUDGET_RASTER_PAINT_PASSES 512
368
#endif
369
370
/* Sweeping an outline costs a small fraction of the area of its mask, and
371
 * far less than the floor at any size, so a very large mask gets just a
372
 * few times its own. */
373
#ifndef HB_BUDGET_RASTER_DRAW_PASSES
374
#define HB_BUDGET_RASTER_DRAW_PASSES 4
375
#endif
376
377
/* One raster draw session, in accumulated non-horizontal edges. */
378
#ifndef HB_RASTER_MAX_DRAW_EDGES
379
#define HB_RASTER_MAX_DRAW_EDGES ((int64_t) 1 << 20)
380
#endif
381
382
/* Times the raster flatteners halve one curve.  A curve four times the
383
 * size takes one more: glyphs take 8 at 8,192 pixels per em and 11 at a
384
 * million, which is about as far as float coordinates can tell a flat
385
 * curve from a bent one.  A curve still not flat at this depth ends the
386
 * outline; no more of it is accumulated. */
387
#ifndef HB_RASTER_MAX_FLATTEN_DEPTH
388
#define HB_RASTER_MAX_FLATTEN_DEPTH 12
389
#endif
390
391
/* Compiling one AAT feature map: morx/mort chains and chain feature
392
 * records visited for each range of the text with its own set of
393
 * features, plus extra for each range a chain keeps rather than merges
394
 * into the previous one, since those are what the map stores.  The
395
 * ranges come from the caller's features and the chains from the font,
396
 * so neither input bounds their product.  Once exhausted, the last
397
 * range compiled extends to the end of the text. */
398
#ifndef HB_BUDGET_AAT_MAP
399
#define HB_BUDGET_AAT_MAP ((int64_t) 1 << 24)
400
#endif
401
402
/* One dependency graph build.  A few bytes of Coverage or ClassDef range
403
 * can name any number of glyphs, so the glyph sets built from them are
404
 * charged per page: for the work of expanding them, and for the memory
405
 * they hold once the graph keeps a copy.  A contextual rule can be shared
406
 * by any number of glyphs or classes, so the label built for each input
407
 * position it has lookup records for is charged per requirement of the
408
 * rule.  Exceeding the budget fails the build. */
409
#ifndef HB_BUDGET_DEPEND
410
#define HB_BUDGET_DEPEND ((int64_t) 1 << 26)
411
#endif
412
413
/* One GSUB glyph-closure session, in records (glyphs, offsets, ranges,
414
 * rules) walked.  HB_MAX_LOOKUP_VISIT_COUNT bounds how many times lookups
415
 * are entered per round, not what one visit walks: through shared offsets
416
 * a subtable can walk many times the size of its table, and every glyph
417
 * the closure gains makes all lookups visitable again.  The glyph set
418
 * kept for each visited lookup is charged per page, for the memory it
419
 * holds. */
420
#ifndef HB_BUDGET_LAYOUT_CLOSURE
421
#define HB_BUDGET_LAYOUT_CLOSURE ((int64_t) 1 << 28)
422
#endif
423
424
425
/* One instancing session: all the tuple variations of one table.
426
 * Limiting an axis splits every tuple that uses it into up to six, so
427
 * tuples multiply with each limited axis.  The copies are charged to a
428
 * budget that starts at MIN and earns FACTOR times each source tuple,
429
 * in tuple_delta_t::get_cost () units of roughly eight bytes.
430
 * A FeatureVariations condition value costs a dozen bytes and any number
431
 * of them can name one VarStore row; what is left of the budget also pays
432
 * for each walk over the regions and tuples of that row, and for each
433
 * tuple copied when the condition needs a private row. */
434
#ifndef HB_BUDGET_INSTANCER_FACTOR
435
#define HB_BUDGET_INSTANCER_FACTOR 128
436
#endif
437
#ifndef HB_BUDGET_INSTANCER_MIN
438
#define HB_BUDGET_INSTANCER_MIN ((int64_t) 1 << 22)
439
#endif
440
441
442
/* Instancing one whole gvar or cvar table in the subsetter, in points.
443
 * Every tuple is expanded to one entry per point of its glyph (per cvt
444
 * value), however few of them it refers to; a tuple takes a dozen bytes
445
 * and a run of repeated glyf points a fraction of a byte each, so the
446
 * size of the font does not bound the product.  The budget is this many
447
 * points per byte of the table, but no less than the minimum; exceeding
448
 * it fails the table. */
449
/* The same table-wide allowance also covers per-axis decoding, retained
450
 * axis maps (including copies made by splitting), and compiled coordinates. */
451
#ifndef HB_BUDGET_SUBSET_TUPLE_POINTS_FACTOR
452
#define HB_BUDGET_SUBSET_TUPLE_POINTS_FACTOR 64
453
#endif
454
#ifndef HB_BUDGET_SUBSET_TUPLE_POINTS_MIN
455
#define HB_BUDGET_SUBSET_TUPLE_POINTS_MIN ((int64_t) 1 << 20)
456
#endif
457
458
459
/* Decoded glyf points a subset plan keeps for partially instancing gvar:
460
 * one per byte of the source glyf table, but no fewer than this.  Repeated
461
 * flags and loca entries that share glyph data let a font declare far more
462
 * points than it has bytes.  Exceeding the budget fails the plan. */
463
#ifndef HB_BUDGET_SUBSET_CONTOUR_POINTS
464
#define HB_BUDGET_SUBSET_CONTOUR_POINTS ((int64_t) 1 << 23)
465
#endif
466
467
468
/* One avar2 partial-instancing plan, in region tents visited to bound the
469
 * final coordinates each axis can reach.  A delta-set row can list a region
470
 * any number of times and axes can share a row, so the table size does not
471
 * bound that work.  An axis whose exact bounds do not fit what is left gets
472
 * the looser interval bounds; once exhausted, the remaining axes get no
473
 * range and are not detected as self-contained.  Either way the instance
474
 * stays correct, only less optimized: those ranges only cull variation
475
 * data that cannot be reached, and a pinned axis not found self-contained
476
 * stays in fvar as a hidden pin. */
477
#ifndef HB_BUDGET_SUBSET_AVAR2_RANGES
478
#define HB_BUDGET_SUBSET_AVAR2_RANGES ((int64_t) 1 << 26)
479
#endif
480
481
482
/* The instancer rebuilds an ItemVariationStore from a dense delta matrix,
483
 * one int per (row, region) pair.  In the font a row only pays for the
484
 * regions of its own VarData, so a small font can ask for a huge matrix.
485
 * These are flat ceilings on that one allocation: a proportional bound
486
 * would reject legitimate optimizer output, where several VarData use
487
 * disjoint region subsets so the dense matrix is much wider than any one
488
 * VarData.  Exceeding either limit fails instancing of that store. */
489
#ifndef HB_SUBSET_MAX_VARSTORE_ROWS
490
#define HB_SUBSET_MAX_VARSTORE_ROWS (1u << 21)
491
#endif
492
493
#ifndef HB_SUBSET_MAX_VARSTORE_DELTAS
494
#define HB_SUBSET_MAX_VARSTORE_DELTAS ((uint64_t) 1 << 26)
495
#endif
496
497
498
/* What a font's Wasm module may use, unless HB_NO_WASM_BUDGET is defined.
499
 *
500
 * Memory, in bytes: a fixed allowance, plus so many times the size of
501
 * the font, plus so many times the size of the buffer's contents.  The
502
 * shapers we measured start at 1MiB to 16MiB whatever the font, and
503
 * grow by up to 3.7KiB for each character, 93 times what the character
504
 * takes in the buffer.
505
 *
506
 * Instructions, in one call: a fixed allowance, which is also what
507
 * shape_plan_create() gets, plus so many for each item in the buffer.
508
 * The runtime counts in an int, so the sum stops at INT_MAX however
509
 * long the text.  Graphite compiled to Wasm runs up to 24 thousand
510
 * instructions for each character, and 53 million in
511
 * shape_plan_create().  The example shapers that measure the distance
512
 * between glyph outlines run 1.7 to 3.5 million. */
513
#ifndef HB_WASM_MAX_MEMORY_MIN
514
#define HB_WASM_MAX_MEMORY_MIN (32u << 20)
515
#endif
516
#ifndef HB_WASM_MAX_MEMORY_FACE_FACTOR
517
#define HB_WASM_MAX_MEMORY_FACE_FACTOR 2
518
#endif
519
#ifndef HB_WASM_MAX_MEMORY_BUFFER_FACTOR
520
#define HB_WASM_MAX_MEMORY_BUFFER_FACTOR 128
521
#endif
522
#ifndef HB_WASM_MAX_INSTRUCTIONS_MIN
523
#define HB_WASM_MAX_INSTRUCTIONS_MIN (1 << 27)
524
#endif
525
#ifndef HB_WASM_MAX_INSTRUCTIONS_FACTOR
526
#define HB_WASM_MAX_INSTRUCTIONS_FACTOR (1 << 22)
527
#endif
528
529
/* Handles a Wasm module instance can hold at once: the face, the font
530
 * and the buffer it is given, and the faces and fonts it creates.  At
531
 * the limit, creating one more fails. */
532
#ifndef HB_WASM_MAX_HANDLES
533
#define HB_WASM_MAX_HANDLES 256
534
#endif
535
536
537
#ifndef HB_REPACKER_MAX_ITERATIONS
538
#define HB_REPACKER_MAX_ITERATIONS 500
539
#endif
540
541
#ifndef HB_REPACKER_MAX_VERTICES
542
#define HB_REPACKER_MAX_VERTICES 800000
543
#endif
544
545
#ifndef HB_REPACKER_MAX_SPACES
546
#define HB_REPACKER_MAX_SPACES 8000
547
#endif
548
549
550
#endif /* HB_LIMITS_HH */