Panic: u16 overflow in name.rs when a name record's offset + length exceeds 65535

Aperta Adatta ai principianti
#30 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
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Leggi src/name.rs, in particolare subset_table intorno alle due aggiunte individuate nell’issue. Esegui la riproduzione fornita o cargo test per osservare l’overflow, quindi verifica che gli offset non validi restituiscano un errore invece di causare un panic e che gli offset di stringa accumulati non vadano in overflow.

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

Descrizione

subset panics with attempt to add with overflow when a name record's offset + length exceeds 65535, in any build with overflow checks (debug builds, cargo test, fuzzing):

thread 'main' panicked at subsetter-0.2.6/src/name.rs:48:20:
attempt to add with overflow

subset_table in src/name.rs adds record.string_offset + record.length as u16 (line 48), and cur_storage_offset += record.length (line 53) can overflow the same way when the kept strings add up to more than 64 KiB. In release builds the first sum wraps, storage.get(..) returns None and the call ends in Err(SubsetError); the second can wrap silently and write wrong string offsets.

To reproduce with subsetter 0.2.6 (default-features = false) and the font below (696 bytes, a minimal TrueType font whose name table has a single record: platform 3, encoding 1, language 0x409, name ID 1, length 4, offset 0xFFFE):

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

cargo run panics as above; cargo run --release prints Err(SubsetError).

name-overflow.ttf, base64 (decode with base64 -d > name-overflow.ttf)
AAEAAAAKAIAAAwAgT1MvMmKwXBUAAAEoAAAAYGNtYXABSgEcAAABnAAAAExnbHlmC4EjVwAAAgAA
AACAaGVhZMSNyOUAAACsAAAANmhoZWEF1AGWAAAA5AAAACRobXR4CMoAlgAAAYgAAAAUbG9jYQAA
AXAAAAHoAAAAGG1heHAACwANAAABCAAAACBuYW1lAFQEUgAAAoAAAAAWcG9zdP+fADIAAAKYAAAA
IAABAAAAAQAAIE34C18PPPUACwPoAAAAAHwlncAAAAAA5vHm7QAAAAACWANSAAAACAACAAEAAAAA
AAEAAAMg/zgAWgJYAAAAAAJYAAEAAAAAAAAAAAAAAAAAAAAFAAEAAAAFAAQAAQAGAAIAAgAAAAAA
AAAAAAAAAAACAAEABAHCAZAABQAAAooCWAAAAEsCigJYAAABXgAyAPoAAAAAAAAAAAAAAAAAAAAD
AAAAAAAAAAAAAAAAT1dSVABAACAAwQMg/zgAWgOEAPoAAAABAAAAAAH0ArwAAAAgAAAB9AAyAPoA
AAJYAAABLABkAlgAAAAAAAIAAAADAAAAFAADAAEAAAAUAAQAOAAAAAoACAACAAIAIABBALQAwf//
AAAAIABBALQAwf///+H/wf9P/0MAAQAAAAAAAAAAAAAAAAAAAAAAJAAAACQAAABEAAAAZAAAAIAA
AQAyAAABwgK8AAMAAAEBAQEAMgAAAZAAAAAAArwAAP1EAAAAAQAAAAACWAK8AAIAAAEBAQAAASwB
LAAAArz9RAAAAAABAGQCWAD6Au4AAgAAAQEBAGQAZAAyAlgAlv/OAAAA//8AAAAAAlgDUgAjAAIA
AAAAAAMAAwBkAGQAAAAAAAEAEgADAAEECQABAAT//gBBAEIAAAADAAAAAAAA/5wAMgAAAAAAAAAA
AAAAAAAAAAAAAAAA

Doing the arithmetic in usize or with checked_add, and returning MalformedFont when it does not fit, would make this an error. Found by fuzzing subsetter through the font crate of officewright; until it is fixed we call subset inside catch_unwind.

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.