cmap format 4 drops glyph IDs above 32767 in the glyphIdArray path
Nadie ha tomado este issue todavía.
- #248 de @msl2246 — cerrado sin fusionar
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
Línea de trabajo
El error está en la rama glyphIdArray del Formato 4 en src/tables/cmap/format4.rs, alrededor de las líneas 85-93. Lee cómo se hacen la comprobación de entradas cero y la suma de idDelta, y luego ejecuta el reproductor sintético del issue para ver que se devuelve None para 0xE123. Está terminado cuando esa prueba devuelve Some(GlyphId(0x8001)), las pruebas cmap existentes en tests/tables/cmap.rs siguen pasando y se añade una prueba de regresión allí.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
In the Format 4 branch where idRangeOffset is nonzero, Subtable4::glyph_index casts the glyphIdArray entry to i16, adds idDelta, and tries to convert the signed result back to u16. When the correct result is above 32767, the signed intermediate is negative and the lookup returns None. As a result, text renderers can treat mapped characters as missing and use a fallback font. This can affect large CJK fonts.
The bug is present in the current release, 0.25.1, and in main at 0c7291223fe9e0bc2808f0255cb991066eedd796. Release v0.25.1 · Format 4 lookup on main
OpenType defines glyphIdArray entries as unsigned 16-bit values. A zero entry denotes a missing glyph. For a nonzero entry, the glyph ID is the entry plus idDelta modulo 65536. OpenType cmap specification, Format 4
Minimal reproduction
Add ttf-parser = "=0.25.1" under [dependencies] in a Rust library crate. Put this test in src/lib.rs and run cargo test. The entire subtable is synthetic and contains one mapping and the required sentinel.
#[test]
fn format4_indirect_lookup_preserves_high_glyph_ids() {
use ttf_parser::{cmap::Subtable4, GlyphId};
// Synthetic Format 4 subtable with one mapped code and a sentinel.
let data = [
0x00, 0x04, 0x00, 0x22, 0x00, 0x00, // format, length, language
0x00, 0x04, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, // search parameters
0xE1, 0x23, 0xFF, 0xFF, // endCode
0x00, 0x00, // reservedPad
0xE1, 0x23, 0xFF, 0xFF, // startCode
0x00, 0x00, 0x00, 0x01, // idDelta
0x00, 0x04, 0x00, 0x00, // idRangeOffset
0x80, 0x01, // glyphIdArray
];
let subtable = Subtable4::parse(&data).unwrap();
assert_eq!(subtable.glyph_index(0xE123), Some(GlyphId(0x8001)));
}
- Expected —
Some(GlyphId(0x8001))(32769). - Actual —
None.
Proposed fix
Add the delta with unsigned 16-bit wrapping arithmetic after the existing zero-entry check. Casting idDelta to u16 preserves its value modulo 65536, including for negative deltas.
diff --git a/src/tables/cmap/format4.rs b/src/tables/cmap/format4.rs
--- a/src/tables/cmap/format4.rs
+++ b/src/tables/cmap/format4.rs
@@ -88,8 +88,8 @@
if glyph_array_value == 0 {
return None;
}
- let glyph_id = (glyph_array_value as i16).wrapping_add(id_delta);
- return u16::try_from(glyph_id).ok().map(GlyphId);
+ let glyph_id = glyph_array_value.wrapping_add(id_delta as u16);
+ return Some(GlyphId(glyph_id));
}
} else {
I can open a PR with the fix and a synthetic regression test in tests/tables/cmap.rs.
- Lenguaje dominante
- Rust
- Estrellas
- 798
- Forks
- 96
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
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 harfbuzz/ttf-parser
-
GPOS PairPosFormat1: device/VariationIndex offsets in PairValueRecords are resolved from the wrong base, so they are always droppedPosiblemente ocupada @mamicicekel la tomó hace 7 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 67/100
harfbuzz/ttf-parser#245 · 1 comentario ·
-
chore: release 0.26.0Quizá libre de nuevo @alerque la tomó hace 117 días y no hay ningún pull request abierto. Abierto
harfbuzz/ttf-parser#242 · 3 comentarios · 1 reacción · 2 asignados ·
-
help wanted
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
harfbuzz/ttf-parser#241 · 2 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
harfbuzz/ttf-parser#230 · 26 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
harfbuzz/ttf-parser#217 · 6 comentarios ·
Todos los issues de harfbuzz/ttf-parser
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
aptos-labs/aptos-core#21119 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 8 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
romnn/pdfium-embed#2 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
romnn/bumpversion#11 ·