cmap format 4 drops glyph IDs above 32767 in the glyphIdArray path
Nessuno ha ancora preso questa issue.
- #248 di @msl2246 — chiusa senza merge
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Il bug si trova nel ramo glyphIdArray del Formato 4 in src/tables/cmap/format4.rs, intorno alle righe 85-93. Leggi come vengono eseguiti il controllo delle voci zero e la somma di idDelta, poi esegui il repro sintetico dell'issue per vedere che viene restituito None per 0xE123. Il lavoro è completo quando quel test restituisce Some(GlyphId(0x8001)), i test cmap esistenti in tests/tables/cmap.rs continuano a passare e viene aggiunto lì un test di regressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Rust
- Stelle
- 798
- Fork
- 96
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di harfbuzz/ttf-parser
-
GPOS PairPosFormat1: device/VariationIndex offsets in PairValueRecords are resolved from the wrong base, so they are always droppedForse già presa @mamicicekel l’ha presa 7 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
harfbuzz/ttf-parser#245 · 1 commento ·
-
chore: release 0.26.0Forse di nuovo libera @alerque l’ha presa 117 giorni fa e non c’è nessuna pull request aperta. Aperta
harfbuzz/ttf-parser#242 · 3 commenti · 1 reazione · 2 assegnatari ·
-
help wanted
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
harfbuzz/ttf-parser#241 · 2 commenti ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
harfbuzz/ttf-parser#230 · 26 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
harfbuzz/ttf-parser#217 · 6 commenti ·
Tutte le issue di harfbuzz/ttf-parser
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
aptos-labs/aptos-core#21119 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 8 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
romnn/pdfium-embed#2 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
romnn/bumpversion#11 ·