Skip to content

Commit 15156d7

Browse files
zeonzipwezm
authored andcommitted
Add glyph substituion limit in GSUB for all multiplesubst substitutions
1 parent 2f82fbd commit 15156d7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/gsub.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::unicode::VariationSelector;
2727
use crate::{tag, GlyphId};
2828

2929
const SUBST_RECURSION_LIMIT: usize = 2;
30+
const MAX_GLYPHS: usize = 10_000;
3031

3132
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
3233
pub struct FeatureInfo {
@@ -462,6 +463,10 @@ fn multiplesubst<T: GlyphData>(
462463
) -> Result<Option<usize>, ParseError> {
463464
match multiplesubst_would_apply(subtables, i, glyphs)? {
464465
Some(sequence_table) => {
466+
if sequence_table.substitute_glyphs.len() + glyphs.len() >= MAX_GLYPHS {
467+
return Err(ParseError::LimitExceeded);
468+
}
469+
465470
if !sequence_table.substitute_glyphs.is_empty() {
466471
let first_glyph_index = sequence_table.substitute_glyphs[0];
467472
glyphs[i].glyph_index = first_glyph_index;

src/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ pub struct MultipleSubst {
14501450
}
14511451

14521452
pub struct SequenceTable {
1453-
pub substitute_glyphs: Vec<u16>,
1453+
pub substitute_glyphs: Vec<GlyphId>,
14541454
}
14551455

14561456
impl ReadBinaryDep for MultipleSubst {

0 commit comments

Comments
 (0)