read_fonts/limits.rs
1//! Limits applied when interpreting font data.
2//!
3//! Font files can describe structures that recurse, refer to themselves, or are
4//! simply enormous. Nothing here comes from the OpenType specification: these
5//! are the bounds this crate places on how much work one operation will do
6//! before giving up, so that a malformed or hostile font cannot turn a parse
7//! into a hang.
8
9/// Maximum depth for structures that nest.
10///
11/// Applies to composite glyph trees, nested variation data, layout lookup
12/// nesting, and colour graph traversal.
13///
14/// Matches HarfBuzz's [`HB_MAX_NESTING_LEVEL`].
15///
16/// [`HB_MAX_NESTING_LEVEL`]: https://github.com/harfbuzz/harfbuzz/blob/724ef405f3a0a0b2792c7a575d1f3341b41ca950/src/hb-limits.hh#L53
17pub const MAX_RECURSION_DEPTH: usize = 64;
18
19/// Maximum number of points in a single assembled outline.
20///
21/// A composite glyph accumulates the points of every component in its tree, so
22/// unlike the point count of one simple glyph this is not bounded by the
23/// format. A contour end point is a `u16`, so the last point an outline can
24/// name is `u16::MAX`, and it holds one more than that.
25pub const MAX_OUTLINE_POINTS: usize = u16::MAX as usize + 1;
26
27/// Maximum number of references followed while assembling one composite
28/// glyph, whether a [`glyf`] component tree or a [`VARC`] graph.
29///
30/// Bounds the total work for a graph that fans out at every level, which the
31/// depth limit alone does not.
32///
33/// [`glyf`]: crate::tables::glyf
34/// [`VARC`]: crate::tables::varc
35pub const MAX_COMPOSITE_EDGES: usize = 2048;
36
37/// Maximum number of scripts visited in a layout table's script list.
38///
39/// Matches HarfBuzz's `HB_MAX_SCRIPTS` in [`hb-limits.hh`].
40///
41/// [`hb-limits.hh`]: https://github.com/harfbuzz/harfbuzz/blob/main/src/hb-limits.hh
42#[cfg(feature = "std")]
43pub const MAX_SCRIPTS: u16 = 500;
44
45/// Maximum number of language systems visited in a layout table's script list.
46///
47/// Matches HarfBuzz's `HB_MAX_LANGSYS` in [`hb-limits.hh`].
48///
49/// [`hb-limits.hh`]: https://github.com/harfbuzz/harfbuzz/blob/main/src/hb-limits.hh
50#[cfg(feature = "std")]
51pub const MAX_LANGSYS: u16 = 2000;
52
53/// Maximum total number of feature indices referenced by the language systems
54/// visited when pruning a layout table's language systems.
55///
56/// Matches HarfBuzz's `HB_MAX_LANGSYS_FEATURE_COUNT` in [`hb-limits.hh`].
57///
58/// [`hb-limits.hh`]: https://github.com/harfbuzz/harfbuzz/blob/main/src/hb-limits.hh
59#[cfg(feature = "std")]
60pub const MAX_LANGSYS_FEATURE_COUNT: u32 = 50000;
61
62/// Maximum total number of feature indices visited across the language
63/// systems of a layout table.
64///
65/// Matches HarfBuzz's `HB_MAX_FEATURE_INDICES` in [`hb-limits.hh`].
66///
67/// [`hb-limits.hh`]: https://github.com/harfbuzz/harfbuzz/blob/main/src/hb-limits.hh
68#[cfg(feature = "std")]
69pub const MAX_FEATURE_INDICES: u16 = 8000;
70
71/// Maximum number of lookups visited by one layout closure operation.
72///
73/// Matches HarfBuzz's `HB_MAX_LOOKUP_VISIT_COUNT` in [`hb-limits.hh`].
74///
75/// [`hb-limits.hh`]: https://github.com/harfbuzz/harfbuzz/blob/main/src/hb-limits.hh
76#[cfg(feature = "std")]
77pub const MAX_LOOKUP_VISIT_COUNT: u16 = 35000;