Panic: unreachable!() in RealNumber::write when a CFF DICT real number overflows f32

Aperta Adatta ai principianti
#31 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
83/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Inizia da src/cff/number.rs, leggendo RealNumber::parse e RealNumber::write; l’issue identifica il parsing che va in overflow e il percorso che provoca il panic. Riproduci il problema con il font fornito e conferma che il font non modificato funziona. Il lavoro è completato quando il real che va in overflow viene rifiutato come font malformato invece di provocare un panic, con un controllo di regressione per questo comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

subset panics on a CFF font whose DICT holds a real number too large for f32, in debug and release builds alike:

thread 'main' panicked at subsetter-0.2.6/src/cff/number.rs:112:22:
internal error: entered unreachable code

RealNumber::parse parses the nibble string with str::parse::<f32>(), which returns inf for an exponent past the f32 range instead of failing. RealNumber::write then formats the value with format!("{}", self.0), gets "inf", and hits unreachable!() on the i. The backtrace goes through rewrite_top_dict_index (src/cff/dict/top_dict.rs:115), but any DICT that is written back with a real operand takes the same path.

To reproduce with subsetter 0.2.6 (default-features = false) and the font below (640 bytes, a minimal CFF OpenType font with two glyphs, where the first FontMatrix operand in the Top DICT is changed from 48828125E-11 to 48828125E99, i.e. the bytes 1e 48 82 81 25 c1 1f to 1e 48 82 81 25 b9 9f):

fn main() {
    let data = std::fs::read("cff-real-inf.otf").unwrap();
    let remapper = subsetter::GlyphRemapper::new();
    println!("{:?}", subsetter::subset(&data, 0, &remapper).map(|font| font.len()));
}

cargo run and cargo run --release both panic as above. The unmodified font prints Ok(476).

cff-real-inf.otf, base64 (decode with base64 -d > cff-real-inf.otf)
T1RUTwAJAIAAAwAQQ0ZGID2FLQsAAAIQAAAAZU9TLzJBOEHdAAABAAAAAGBjbWFwAAwAlAAAAbwA
AAA0aGVhZC9WaxIAAACcAAAANmhoZWEImgEuAAAA1AAAACRobXR4ArwAZAAAAngAAAAGbWF4cAAC
UAAAAAD4AAAABm5hbWU6H0HRAAABYAAAAFpwb3N0AAMAAAAAAfAAAAAgAAEAAAABAAD/pwTcXw88
9QADCAAAAAAA5vQRrwAAAADm9BGvAGQAAAH0ArwAAAADAAIAAAAAAAAAAQAABkD+cAAAAlgAZABk
AfQAAQAAAAAAAAAAAAAAAAAAAAEAAFAAAAIAAAADAlgBkAAFAAQAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAA/Pz8/AAAAQQBBAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAACAAAAAAAAQANgABAAAAAAABAAUAAAABAAAAAAACAAcABQADAAEECQABAAoADAADAAEE
CQACAA4AFlJlcHJvUmVndWxhcgBSAGUAcAByAG8AUgBlAGcAdQBsAGEAcgAAAAAAAgAAAAMAAAAU
AAMAAQAAABQABAAgAAAABAAEAAEAAABB//8AAABB////wAABAAAAAAADAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAQAEAQABAQEGUmVwcm8AAQEBJvgbAh5IgoEluZ+Lix5IgoElwR+LiwwH
74v4iPlQBc8Pi/AS0hEAAQEBBlJlcHJvAAAAACIAAgEBDRn47O8W+CT5UPwkBg747O8W+CT5UPwk
Bg4AAAACWABkAGQAAA==

SHA-256: 5c4f925da37caa1009b87e42eaa5410b59a69f386b617825f77c0339adc7ed6f

Returning None from RealNumber::parse when the parsed value is not finite would make this a MalformedFont error; a finite f32 always formats with {} as digits, . and - only, so write would then be safe. Found by fuzzing subsetter through the font registration of inkoxide; until it is fixed we check the DICT reals ourselves before calling subset.

Lingua principale
Rust
Stelle
61
Fork
16
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di typst/subsetter

Tutte le issue di typst/subsetter

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.