Skip to content

pdf: checked_add for CFF Private DICT and Type 1 RD offsets from the file - #1482

Merged
bflatastic merged 2 commits into
storytold:mainfrom
midasmatterhorn:fix/font-offset-overflow
Oct 16, 2026
Merged

bflatastic merged 2 commits into
storytold:mainfrom
midasmatterhorn:fix/font-offset-overflow

Conversation

@midasmatterhorn

Copy link
Copy Markdown
Contributor

Three file-supplied offset + length additions in the font readers were still unchecked: the CFF Private DICT slice (d.get(off..off + size)), the Private DICT local-Subrs lookup (index(d, off + s)), and the Type 1 binary-item reader (priv_.get(q..q + n)) add numbers taken straight from the font file, where a huge real saturates to usize::MAX on cast. On debug/test builds (overflow checks on) a crafted font — a CFF top DICT with Private [1E300 1E300], or a Type 1 /Subrs entry with RD length 18446744073709551615 — makes the add overflow and panic the importer, violating the checked-arithmetic rule in AGENTS.md.

All three sites now use checked_add and fall back to the existing "empty Private DICT" / "skip the damaged item" behaviour. Regression tests build both fixtures and assert the font still parses (.notdef present); both failed with "attempt to add with overflow" before the fix.

Partially addresses #1446 (finding 4, DICT offset overflow). Targeted tests green locally; cargo xtask ci left to the project runners.

# Conflicts:
#	crates/pdf/src/cff.rs
@bflatastic
bflatastic merged commit 19d19a3 into storytold:main Oct 16, 2026
@bflatastic

Copy link
Copy Markdown
Member

Merged, thank you @midasmatterhorn! It landed on main with a batch of community PRs, after a full workspace build and test run on Windows: fmt, clippy -D warnings, all 3,463 tests, layers, assets and wasm. I merged main into the branch to resolve the test conflict with #1477, keeping both tests. It also covers #1567's Type 1 fix, so I closed that one.

@midasmatterhorn

Copy link
Copy Markdown
Contributor Author

Thanks for sorting the test conflict and keeping both tests. Closing #1567 in favour of this one is right — it's a strict subset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants