/work/workdir/UnpackedTarball/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 256 |
33 | | #endif |
34 | | #ifndef HB_BUFFER_MAX_LEN_MIN |
35 | 17.5M | #define HB_BUFFER_MAX_LEN_MIN 65536 |
36 | | #endif |
37 | | #ifndef HB_BUFFER_MAX_LEN_DEFAULT |
38 | 23.6M | #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 | | #define HB_BUFFER_MAX_OPS_FACTOR 4096 |
43 | | #endif |
44 | | #ifndef HB_BUFFER_MAX_OPS_MIN |
45 | 17.5M | #define HB_BUFFER_MAX_OPS_MIN 65536 |
46 | | #endif |
47 | | #ifndef HB_BUFFER_MAX_OPS_DEFAULT |
48 | 23.6M | #define HB_BUFFER_MAX_OPS_DEFAULT 0x1FFFFFFF /* Shaping more than a billion operations? Let us know! */ |
49 | | #endif |
50 | | |
51 | | |
52 | | #ifndef HB_MAX_NESTING_LEVEL |
53 | 0 | #define HB_MAX_NESTING_LEVEL 64 |
54 | | #endif |
55 | | |
56 | | |
57 | | #ifndef HB_MAX_CONTEXT_LENGTH |
58 | 0 | #define HB_MAX_CONTEXT_LENGTH 64 |
59 | | #endif |
60 | | |
61 | | #ifndef HB_MAX_SYLLABLE_LENGTH |
62 | 81.1k | #define HB_MAX_SYLLABLE_LENGTH 64 |
63 | | #endif |
64 | | |
65 | | #ifndef HB_CLOSURE_MAX_STAGES |
66 | | /* |
67 | | * The maximum number of times a lookup can be applied during shaping. |
68 | | * Used to limit the number of iterations of the closure algorithm. |
69 | | * This must be larger than the number of times add_gsub_pause() is |
70 | | * called in a collect_features call of any shaper. |
71 | | */ |
72 | 0 | #define HB_CLOSURE_MAX_STAGES 12 |
73 | | #endif |
74 | | |
75 | | #ifndef HB_MAX_SCRIPTS |
76 | 630 | #define HB_MAX_SCRIPTS 500 |
77 | | #endif |
78 | | |
79 | | #ifndef HB_MAX_LANGSYS |
80 | 756 | #define HB_MAX_LANGSYS 2000 |
81 | | #endif |
82 | | |
83 | | #ifndef HB_MAX_LANGSYS_FEATURE_COUNT |
84 | 0 | #define HB_MAX_LANGSYS_FEATURE_COUNT 50000 |
85 | | #endif |
86 | | |
87 | | #ifndef HB_MAX_FEATURE_INDICES |
88 | 0 | #define HB_MAX_FEATURE_INDICES 8000 |
89 | | #endif |
90 | | |
91 | | #ifndef HB_MAX_LOOKUP_VISIT_COUNT |
92 | 0 | #define HB_MAX_LOOKUP_VISIT_COUNT 35000 |
93 | | #endif |
94 | | |
95 | | #ifndef HB_MAX_GRAPH_EDGE_COUNT |
96 | 0 | #define HB_MAX_GRAPH_EDGE_COUNT 16384 |
97 | | #endif |
98 | | |
99 | | #ifndef HB_VAR_COMPOSITE_MAX_AXES |
100 | 0 | #define HB_VAR_COMPOSITE_MAX_AXES 4096 |
101 | | #endif |
102 | | |
103 | | #ifndef HB_GLYF_MAX_POINTS |
104 | 3.48k | #define HB_GLYF_MAX_POINTS 200000 |
105 | | #endif |
106 | | |
107 | | #ifndef HB_CFF_MAX_OPS |
108 | 0 | #define HB_CFF_MAX_OPS 200000 |
109 | | #endif |
110 | | |
111 | | #ifndef HB_MAX_COMPOSITE_OPERATIONS_PER_GLYPH |
112 | 501k | #define HB_MAX_COMPOSITE_OPERATIONS_PER_GLYPH 64 |
113 | | #endif |
114 | | |
115 | | #ifndef HB_SVG_MAX_PATH_SEGMENTS |
116 | | #define HB_SVG_MAX_PATH_SEGMENTS 262144 |
117 | | #endif |
118 | | |
119 | | #ifndef HB_GPU_DRAW_MAX_CURVES |
120 | | #define HB_GPU_DRAW_MAX_CURVES 65536 |
121 | | #endif |
122 | | |
123 | | /* Total bytes of sub-blobs (gradient color stops, clip outlines) in one |
124 | | * hb_gpu_paint_t walk; exceeding it makes the paint unsupported. */ |
125 | | #ifndef HB_GPU_PAINT_MAX_SUB_BYTES |
126 | | #define HB_GPU_PAINT_MAX_SUB_BYTES ((unsigned) 64 << 20) |
127 | | #endif |
128 | | |
129 | | /* Tiles emitted by one hb_paint_sweep_gradient_tiles() call. Also |
130 | | * sets the angular resolution (2π over this) below which a repeating |
131 | | * color line is filled with its average color instead of tiled; |
132 | | * a repeat/reflect color line whose stops span a tiny angle could |
133 | | * otherwise emit millions of patches while covering 0..2π. */ |
134 | | #ifndef HB_PAINT_MAX_SWEEP_TILES |
135 | 0 | #define HB_PAINT_MAX_SWEEP_TILES 4096 |
136 | | #endif |
137 | | |
138 | | #ifndef HB_SVG_MAX_DOCUMENT_SIZE |
139 | | #define HB_SVG_MAX_DOCUMENT_SIZE ((size_t) 16 << 20) |
140 | | #endif |
141 | | |
142 | | /* Maximum size of one serialized vector document (SVG or PDF) produced by |
143 | | * the vector backends. Bounds output that is not outline-derived -- most |
144 | | * of a path, but especially sweep-gradient meshes and embedded bitmaps -- |
145 | | * which the outline work budget cannot see. vector is one glyph per |
146 | | * context, so a flat cap suffices. Unsigned (not size_t like the SVG-table |
147 | | * limit above) to match hb_vector_buf_t's unsigned length arithmetic. */ |
148 | | #ifndef HB_VECTOR_MAX_DOCUMENT_SIZE |
149 | | #define HB_VECTOR_MAX_DOCUMENT_SIZE ((unsigned) 16 << 20) |
150 | | #endif |
151 | | |
152 | | #ifndef HB_RASTER_MAX_BUFFER_SIZE |
153 | | #define HB_RASTER_MAX_BUFFER_SIZE ((size_t) 1 << 30) |
154 | | #endif |
155 | | |
156 | | /* Maximum surface dimension (pixels per side) when extents are derived |
157 | | * from font data (glyph extents or accumulated outline bounds). Bounds |
158 | | * attacker-controlled allocations; extents set explicitly through |
159 | | * hb_raster_{draw,paint}_set_extents() are not limited. */ |
160 | | #ifndef HB_RASTER_MAX_AUTO_DIMENSION |
161 | | #define HB_RASTER_MAX_AUTO_DIMENSION 4096 |
162 | | #endif |
163 | | |
164 | | /* |
165 | | * Cumulative work budgets. |
166 | | * |
167 | | * The limits above bound work within one subsystem: points per glyf |
168 | | * glyph, ops per CFF charstring, nodes in a COLR or VARC graph, |
169 | | * pixels per raster surface. When one subsystem drives another -- |
170 | | * COLR driving a paint backend, a paint backend or VARC loading |
171 | | * glyf/CFF outlines -- those limits multiply. Each driving session |
172 | | * therefore carries one cumulative budget, initialized once per |
173 | | * top-level entry and only ever decremented, shared by everything |
174 | | * the session consumes. Once a budget is exhausted, further work |
175 | | * is skipped best-effort. |
176 | | */ |
177 | | |
178 | | /* Fixed relative weights. Keep the value in the name so charge sites are |
179 | | * easy to audit; tune the common session cap, not these values. */ |
180 | 0 | #define HB_BUDGET_1 1u |
181 | | #define HB_BUDGET_2 2u |
182 | | #define HB_BUDGET_4 4u |
183 | | #define HB_BUDGET_8 8u |
184 | | #define HB_BUDGET_16 16u |
185 | | #define HB_BUDGET_32 32u |
186 | | #define HB_BUDGET_64 64u |
187 | | #define HB_BUDGET_128 128u |
188 | | #define HB_BUDGET_256 256u |
189 | | #define HB_BUDGET_512 512u |
190 | | #define HB_BUDGET_1024 1024u |
191 | | |
192 | | /* The common finite default for one top-level glyph rendering session. |
193 | | * Nested outline and paint work shares the same live counter. */ |
194 | | #ifndef HB_BUDGET_GLYPH |
195 | 82.3k | #define HB_BUDGET_GLYPH ((int64_t) 1 << 24) |
196 | | #endif |
197 | | |
198 | | /* Precharge COST * MULT. Callers bound COST and MULT structurally, and live |
199 | | * budgets are concrete non-negative values when a session starts. */ |
200 | | static HB_ALWAYS_INLINE bool |
201 | | hb_budget_spend (int64_t &budget, unsigned int cost, unsigned int mult = 1) |
202 | 60.0k | { |
203 | 60.0k | budget -= (int64_t) cost * mult; |
204 | 60.0k | return budget >= 0; |
205 | 60.0k | } 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-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-draw.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-map.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-color.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-fetch.cc:hb_budget_spend(long&, unsigned int, unsigned int) hb-ot-font.cc:hb_budget_spend(long&, unsigned int, unsigned int) Line | Count | Source | 202 | 60.0k | { | 203 | 60.0k | budget -= (int64_t) cost * mult; | 204 | 60.0k | return budget >= 0; | 205 | 60.0k | } |
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-layout.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-ot-math.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-name.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-tag.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-shape.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-style.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-graphite2.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-icu.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-buffer-verify.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-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-ucd.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-buffer-serialize.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) Unexecuted instantiation: hb-subset-input.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-plan.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-plan-layout.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-plan-var.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-table-layout.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-table-var.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-table-cff.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-table-color.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-table-other.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: gsubgpos-context.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-cff1.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-cff2.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-instancer-iup.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-instancer-solver.cc:hb_budget_spend(long&, unsigned int, unsigned int) Unexecuted instantiation: hb-subset-cff-common.cc:hb_budget_spend(long&, unsigned int, unsigned int) |
206 | | |
207 | | /* The flat pixel-work floor for one raster paint session. Pixel and |
208 | | * outline work use separate live counters, so keep this independent of |
209 | | * the common outline budget above. */ |
210 | | #ifndef HB_BUDGET_RASTER_PIXELS |
211 | | #define HB_BUDGET_RASTER_PIXELS ((int64_t) 1 << 26) |
212 | | #endif |
213 | | |
214 | | /* Very large raster surfaces still get a few full-surface operations. */ |
215 | | #ifndef HB_BUDGET_RASTER_PAINT_PASSES |
216 | | #define HB_BUDGET_RASTER_PAINT_PASSES 4 |
217 | | #endif |
218 | | |
219 | | /* One raster draw session, in accumulated non-horizontal edges. */ |
220 | | #ifndef HB_RASTER_MAX_DRAW_EDGES |
221 | | #define HB_RASTER_MAX_DRAW_EDGES ((int64_t) 1 << 20) |
222 | | #endif |
223 | | |
224 | | |
225 | | #ifndef HB_REPACKER_MAX_ITERATIONS |
226 | 0 | #define HB_REPACKER_MAX_ITERATIONS 500 |
227 | | #endif |
228 | | |
229 | | #ifndef HB_REPACKER_MAX_VERTICES |
230 | | #define HB_REPACKER_MAX_VERTICES 800000 |
231 | | #endif |
232 | | |
233 | | #ifndef HB_REPACKER_MAX_SPACES |
234 | | #define HB_REPACKER_MAX_SPACES 8000 |
235 | | #endif |
236 | | |
237 | | |
238 | | #endif /* HB_LIMITS_HH */ |