Panic: u16 overflow of the stem-hint count in charstring.rs when a glyph declares more than 65535 hints
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 67/100
Línea de trabajo
Start in subsetter-0.2.6/src/cff/charstring.rs, at Decompiler::count_hints and the reported hint_count addition. Read how its errors are returned, then add a regression test using the supplied CFF reproduction or a focused charstring test. Done means excessive stem hints return an error instead of panicking or wrapping; run cargo test.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
subset panics on a CFF glyph that declares more than 65535 stem hints, in any build with overflow checks (debug builds, cargo test, fuzzing):
thread 'main' panicked at subsetter-0.2.6/src/cff/charstring.rs:171:9:
attempt to add with overflow
Decompiler::count_hints adds the hints of each stem operator to hint_count, a u16 (self.hint_count += elements.len() as u16 / 2). A glyph whose charstring, through subroutines, runs hstem with 48 operands 2731 times or more overflows it. Without overflow checks the count wraps silently, and the size of a following hintmask would be computed from the wrapped count. This happens with 0.2.6 and with main (b0adcc1).
To reproduce with subsetter 0.2.6 (default-features = false). The font is built for this report:
fn main() {
// A minimal OpenType CFF font, 355 bytes, whose one glyph declares 72,000 stem
// hints: global subroutine 0 is 48 operands and hstem (24 hints), subroutine 1 calls
// it 60 times, subroutine 2 calls subroutine 1 50 times, and the charstring calls
// subroutine 2 once, then endchar.
let hex = "4f54544f000100100000000043464620000000000000001c000001470100040100010101024100010101121d0000013d111d000000021d000001451200000003020001003300ac01118b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b010b201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d201d0b211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d211d0b0001010104221d0e8b14";
let data: Vec<u8> = (0..hex.len())
.step_by(2)
.map(|i| u8::from_str_radix(&hex[i..i + 2], 16).unwrap())
.collect();
let remapper = subsetter::GlyphRemapper::new();
println!("{:?}", subsetter::subset(&data, 0, &remapper).map(|font| font.len()));
}
cargo run panics as above; cargo run --release prints Ok(147168).
It was found while reviewing how officewright guards against subsetter panics; until it is fixed, our call to subset turns the panic into an error.
A possible fix: add with checked_add and return CFFError on overflow. The Type 2 charstring format also limits a glyph to 96 stem hints (Technical Note #5177, Appendix B), so refusing more than that would fix it too.
- Lenguaje dominante
- Rust
- Estrellas
- 61
- Forks
- 16
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de typst/subsetter
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
head table bounding box is not recalculated for variable font instancesPosiblemente ocupada @khaledhosny la tomó hace 16 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 56/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 45/100
Todos los issues de typst/subsetter
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Input: placeholder drawn in the text colour when the empty Input is focused but not yet editedAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
pierreaubert/gpui-toolkit#114 ·
Los mantenedores suelen responder en 1 día
-
BibLaTeX `type` keys like `phdthesis`, `mathesis`, `techreport` are printed raw instead of localizedAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
remove the use of `forget`Abiertogood first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Los mantenedores suelen responder en 1 día
-
compiler
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
HerringtonDarkholme/hd-lang#1853 ·
Los mantenedores suelen responder en 1 día