Sanitizer for OpenType (OTS) is a small library which parses OpenType (TTF/OTF) and WOFF/WOFF2 files (usually from @font-face
) and attempts to validate and sanitize them. This library is primarily intended to be used with Chromium. We hope this reduces the attack surface of the system font libraries.
What the sanitizer does is as follows:
By transcoding fonts in this way, it is ensured that:
Name | Mandatory table? | Supported by OTS? | Note |
---|---|---|---|
sfnt | Yes | Yes | Overlapped tables are not allowed; it is treated as a fatal parser error. |
maxp | Yes | Yes | |
head | Yes | Yes | |
hhea | Yes | Yes | |
hmtx | Yes | Yes | |
name | Yes | Yes | |
OS/2 | Yes | Yes | |
post | Yes | Yes | |
cmap | Yes | Partially | see below |
glyf | Yes, for TrueType fonts | Yes | TrueType bytecode is supported, but OTS does not validate it. |
loca | Yes, when glyf table exists | Yes | |
CFF | Yes, for OpenType fonts | Yes | OpenType bytecode is also supported, and OTS does validate it. |
cvt | No | Yes | Though this table is not mandatory, OTS can't drop the table from a transcoded font since it might be referred from other hinting-related tables. Errors on this table should be treated as fatal. |
fpgm | No | Yes | Ditto. |
prep | No | Yes | Ditto. |
VDMX | No | Yes | This table is important for calculating the correct line spacing, at least on Chromium Windows and Chromium Linux. |
hdmx | No | Yes | |
gasp | No | Yes | |
VORG | No | Yes | |
LTSH | No | Yes | |
kern | No | Yes | |
GDEF | No | Yes | |
GSUB | No | Yes | |
GPOS | No | Yes | |
morx | No | No | |
jstf | No | No | |
vmtx | No | Yes | |
vhea | No | Yes | |
EBDT | No | No | We don't support embedded bitmap strikes. |
EBLC | No | No | Ditto. |
EBSC | No | No | Ditto. |
bdat | No | No | Ditto. |
bhed | No | No | Ditto. |
bloc | No | No | Ditto. |
DSIG | No | No | |
All other tables | - | No |
Please note that OTS library does not parse “unsupported” tables. These unsupported tables never appear in a transcoded font.
The following 9 formats are supported:
All other types of subtables are not supported and do not appear in transcoded fonts.
With regards to 8 mandatory tables, glyph-related tables (glyf
, loca
and CFF
), and hinting-related tables (cvt
, prep
, and fpgm
):
With regards to optional tables (VORG
, gasp
, hdmx
, LTSH
, and VDMX
):
ots::Process()
.OTSStream
interface, a write-only memory stream.MemoryStream
class which implements the OTSStream
interface above.Buffer
class which is a read-only memory stream.ots::Process()
function.sfnt
table parser.Please check the issues page.