Author: Tom Sepez (tsepez@google.com) Target Project: PDFium (core/fxge, standalone, and Chromium integration) Status: Proposed Architecture
PDFium historically relies on FreeType for both binary font table parsing and glyph pixel rasterization. However, the overwhelming majority of historical vulnerabilities in font engines stem from parsing untrusted, malformed font tables (such as embedded TrueType, OpenType, and CFF streams in malicious PDFs).
Project Frankenfonts proposes a hybrid font architecture:
read-fonts + skrifa) Rust crates to parse font tables, decode CMaps, compute metrics, and execute TrueType VM / CFF hinting instructions in safe Rust.FT_Render_Glyph in ftsmooth.c / ftgrays.c) or PDFium’s AGG rasterizer to generate anti-aliased bitmap masks.pdf_use_skia requirement from pdf_enable_fontations, allowing standalone PDFium (including AGG builds) to benefit from memory-safe font parsing.PDF files frequently embed custom, subsetted, or heavily modified font files. Over the last two decades, embedded font parsing in FreeType has been one of the primary attack vectors for remote code execution and memory corruption in document viewers (integer overflows in table offsets, malformed CMap subtables, corrupt CFF charstrings).
FreeType performs two fundamentally distinct tasks:
CMap, Hmtx, OS/2, Name, Post, glyf, CFF) and running Turing-complete bytecode interpreters in C.ftgrays.c) or subpixel LCD masks (ftsmooth.c).FreeType's rasterization math is battle-tested and produces the exact anti-aliasing curves PDFium expects. The risk is located in Task A (Parsing).
┌──────────────────────────────────────────────┐
│ Untrusted PDF Font Data │
└──────────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Fontations Frontend (Pure Safe Rust) │
│ - `read-fonts`: Safe Table Parsing │
│ - `skrifa`: CMaps, Metrics, BBoxes │
│ - `HintingInstance`: TrueType / CFF VM │
│ - `OutlinePen`: Bézier Curve Extraction │
└──────────────────────┬───────────────────────┘
│
▼ Extracted `FT_Outline` / `CFX_Path`
┌──────────────────────────────────────────────┐
│ Rasterization Backend (FreeType / AGG) │
│ - Feeds safe Bézier curves into rasterizer│
│ - FreeType `FT_Render_Glyph` or AGG AA │
└──────────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ CFX_GlyphBitmap │
│ (Anti-Aliased Mask) │
└──────────────────────────────────────────────┘
Because read-fonts and skrifa are written in 100% memory-safe Rust with strict bounds-checking, zero-copy slicing, and fuzz-tested arithmetic, PDFium becomes completely immune to font-table parsing vulnerabilities. FreeType is never exposed to raw untrusted font byte streams.
By feeding Skrifa‘s extracted vector outlines into FreeType’s existing rasterizer (ftsmooth.c / ftgrays.c), the resulting bitmap masks maintain visual fidelity with legacy FreeType output. Subpixel hinting variances inherent to independent TrueType VM implementations are handled via windowed MSE fuzzy test matching and expectation suffixes.
Currently, pdf_enable_fontations is artificially gated on pdf_use_skia = true. Frankenfonts decouples Fontations from Skia:
skrifa and read_fonts are vendored directly via gnrt in //third_party/rust/.pdf_use_agg = true, pdf_use_skia = false) can use Fontations with zero dependencies on Skia.pdfium.gni to assert that pdf_enable_fontations only requires enable_rust = true.PDF_ENABLE_FONTATIONS in BUILD.gn whenever pdf_enable_fontations is enabled.CFX_FontMgr::GetFontBackend() and FPDF_InitLibraryWithConfig() runtime selection in AGG builds.--fontations CLI flag into pdfium_test, pdfium_embeddertests, and pdfium_unittests.skrifahinted_outline() in main.rs using skrifa::outline::HintingInstance.CFX_Face::RenderGlyph() to extract outlines through Skrifa at the target display PPEM scale and rasterize through FT_Render_Glyph().Project Frankenfonts delivers uncompromising memory safety against hostile font exploits in untrusted PDFs paired with FreeType scanline rasterization, keeping standalone PDFium lean, fast, and secure.