Skip to content

fix(font): validate SFNT character map ranges - #1056

Merged
andiwand merged 3 commits into
mainfrom
review/38-sfnt-cmap-bounds
Oct 5, 2026
Merged

andiwand merged 3 commits into
mainfrom
review/38-sfnt-cmap-bounds

Conversation

@andiwand

@andiwand andiwand commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

A malformed format-12 character-map range could wrap indefinitely or expand overlapping ranges repeatedly. The parser now checks character and glyph ranges before it expands them. Like FreeType, a broken or unsupported cmap subtable drops only itself, and the next supported one is used, because a PDF addresses embedded glyphs by ID. A table or name that runs past its end is clipped; a table offset past the end and a zero em size throw.

Keep accepting the unused format-4 terminator offset found in an existing embedded-font fixture. The constraints follow the OpenType cmap specification.

Validation: 60 targeted font/PDF-font tests and three PDF corpus cases pass, with no font parsing warnings. Three focused regression tests cover malformed input and supported-subtable selection.

@andiwand
andiwand force-pushed the review/37-legacy-metadata branch from f6a86bf to 1a5830a Compare October 5, 2026 09:53
Base automatically changed from review/37-legacy-metadata to main October 5, 2026 10:57
andiwand and others added 2 commits October 5, 2026 12:58
A PDF addresses the glyphs of an embedded font by ID, so a refused font
falls back to a substitute and shows the wrong glyphs. Like FreeType, a
broken cmap subtable now drops only itself, and the next supported one is
used. A bad format-4 segment is skipped. A table or name that runs past
its end is clipped, an odd UTF-16 name length and a duplicate table tag
are accepted. A table offset past the end and a zero unitsPerEm still
throw.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gb1fLafqqzehpqPuU6uBfn
@andiwand
andiwand force-pushed the review/38-sfnt-cmap-bounds branch from e1ebcf7 to f470f38 Compare October 5, 2026 11:03
Comment thread src/odr/internal/font/sfnt_font.cpp Outdated
@andiwand
andiwand merged commit b9eef24 into main Oct 5, 2026
9 of 23 checks passed
@andiwand
andiwand deleted the review/38-sfnt-cmap-bounds branch October 5, 2026 11:14
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.

1 participant