Panic: u16 overflow in name.rs when a name record's offset + length exceeds 65535
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Read src/name.rs, especially subset_table around the two additions identified in the issue. Run the supplied reproduction or cargo test to observe the overflow, then check that malformed offsets return an error rather than panic and that accumulated string offsets do not wrap.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Rust
- Stars
- 61
- Forks
- 16
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from typst/subsetter
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
head table bounding box is not recalculated for variable font instancesPossibly taken @khaledhosny claimed this 16 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 56/100
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
-
Difficulty 3/5 Half a day Newbie friendliness 67/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pierreaubert/gpui-toolkit#114 ·
Maintainers usually reply within 1 day
-
BibLaTeX `type` keys like `phdthesis`, `mathesis`, `techreport` are printed raw instead of localizedOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
compiler
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
HerringtonDarkholme/hd-lang#1853 ·
Maintainers usually reply within 1 day
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
pbakaus/impeccable#1462 ·
Maintainers usually reply within 1 day