struetype.h
Fork of the stb_truetype.h v1.26 font header originally from https://github.com/nothings/stb
Here's an example of struetype.h output produced with the ProFont ttf using the foview example program:
The foview example will take a .ttf file and produce a PDF (and a PNG if the character set is small enough, which it usually isn't on modern fonts) visualizing the glyphs defined by the font. It is intended to be a minimal but reasonably useful example of utilizing struetype.h to do something interesting.
This fork makes API changes to address the 2020/2022 CVE reports, which are considered out of scope by upstream. The API changes are (and must be) breaking, since addressing the problems requires knowledge about buffer sizes the original APIs don't provide. Accordingly, we have renamed the header and changed the function names to use a different prefix.
All public functions that inspect a raw font buffer require its exact byte
size. Font initialization validates the SFNT table directory and the required
TrueType or CFF tables before exposing them through stt_fontinfo. Glyph,
kerning, name, SVG, raster, SDF, baking, and atlas paths use bounded reads,
checked allocation arithmetic, recursion and tessellation limits, and graceful
allocation-failure handling. Default bitmap and tessellation limits may be
overridden with STT_MAX_BITMAP_PIXELS and
STT_MAX_TESSELLATION_POINTS before including the implementation.
The test suite applies the historical CVE inputs to every sanitizer-enabled
test executable. It also tests every truncation of a valid font,
deterministically corrupts the file throughout, exercises the baking and atlas
APIs, and injects allocation failures. Sanitizers can be disabled for a
normal build with -DSTRUETYPE_ENABLE_SANITIZERS=OFF.
The specific CVE reports in question are:
- CVE-2022-25516
- CVE-2022-25515
- CVE-2022-25514
- CVE-2020-6623
- CVE-2020-6622
- CVE-2020-6621
- CVE-2020-6620
- CVE-2020-6619
- CVE-2020-6618
- CVE-2020-6617
The test cases are set up in the test directory to be runnable with make test
or ctest, ensuring we can reproduce and test the failure cases. The code and
files are from the GitHub issues associated with these CVEs - see the above
links for more details.
