gfxOTSExpandingMemoryStream::Seek leaves skipped bytes uninitialized, allowing heap memory disclosure through a crafted @font-face cmap
A font sanitizer's expanding memory stream leaves gaps uninitialized when seeking forward, and a crafted cmap table can cause Firefox to read those bytes as a glyph ID. An attacker could measure the resulting advance width to disclose small amounts of heap memory.
Originally disclosed on Mozilla
- Fixed in 4 days
- Paid in 4 months
- Disclosed after 4 days
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Steps to reproduce:
Source review of mozilla-central @ 0f72a20bbd (2026-07-25).
NOT executed; the font binary was NOT assembled. This is the least certain of
my reports — see the confidence note at the end.
Serve a WOFF/OTF via @font-face whose cmap has exactly two encoding records:
1) platform=0, encoding=3, format=4, length=40, segCountX2=6
seg0: 0x0041-0x0041, idRangeOffset=0
seg1: 0xFFFF-0xFFFF, idRangeOffset=0, idDelta=2
seg2: 0xFFFF-0xFFFF, idRangeOffset=0xFFFF (ODD), idDelta=2 <- last seg
2) platform=0, encoding=5, format=14, length=66004+5N,
one variation-selector record with nonDefaultUVSOffset = 66000
plus maxp.numGlyphs=65535 and an hmtx giving each glyph a distinct advance.
Then from content: ctx.measureText("\uFFFF")
Actual results:
The measured advance corresponds to a glyph ID read from uninitialized heap —
roughly 2 attacker-chosen bytes per lookup, repeatable and sprayable within an
attacker-sized ~64 KB window.
FIREFOX-SIDE MECHANISM — verified directly, three links, each a defect on its
own regardless of the rest:
1. gfx/thebes/gfxOTSUtils.h:12-18 — the allocator is raw:
struct gfxOTSMozAlloc {
void* Grow(void* aPtr, size_t aLength) { return moz_xrealloc(aPtr, aLength); }
void* ShrinkToFit(void* aPtr, size_t aLength) { return moz_xrealloc(aPtr, aLength); }
No zeroing; there is no calloc anywhere in the file.
2. gfxOTSUtils.h:70-79 — Seek accepts any position <= mLength, where mLength is
the ALLOCATION size, not the written extent, and performs no zero-fill:
if (position < 0) return false;
if (static_cast<size_t>(position) > mLength) return false;
mOff = position;
return true;
3. gfxOTSUtils.h:42-46 — forget() returns mAlloc.ShrinkToFit(mPtr, mOff), i.e.
the buffer is sized to the highest offset reached. Any gap between the last
write and a forward Seek is therefore INCLUDED in the buffer handed to the
caller, carrying uninitialized heap.
OTS-SIDE CHAIN — read, but not executed:
4. gfx/ots/src/cmap.cc:158-170 — for an odd id_range_offset on the LAST fmt-4
segment, OTS zeroes only its internal copy, commenting "The id_range_offset
value in the transcoded font will not change since this table is not actually
'transcoded' yet." The subtable is stored raw at :251-259 and emitted
verbatim, so the odd value survives — and the strict glyph-array bound at
:236 is skipped for that segment, because the simulation at :219-247 takes
the id_range_offset == 0 branch.
Parse0514 (:532) only requires the parse to END at length; it never requires
the sub-tables to tile the subtable, so the serializer's forward Seek at
:905/:920 leaves the ~66 KB gap.
5. gfx/thebes/gfxFontUtils.cpp:671, :703-710 — limit = aBuf + aLength, where
aLength is the remainder of the WHOLE cmap table, not the subtable
(gfxHarfBuzzShaper.cpp:84, gfxFontUtils.cpp:894). So a 0-65535 byte forward
jump out of the fmt-4 subtable into a sibling subtable passes the bound check.
MapCharToGlyphFormat4 lands deterministically on idx=2, computes
&idRangeOffset[2] + 0xFFFF -> inside the uninitialized gap, passes the limit
check, and returns *(uint16*)uninitialized_heap + 2 as the glyph ID, whose
advance width is directly measurable from script.
Note seg1 puts U+FFFF into Firefox's char map (gfxFontUtils.cpp:256-258) so the
font is selected for it, while seg2 is skipped during validation by
"if (c == 0xFFFF) break;" (:264).
Platforms: affects Windows (DWrite) and macOS (CoreText), where
gfxFont::ProvidesGetGlyph() is false (gfxFont.h:1633). On Linux/Android FreeType
supplies the cmap so link 5 does not apply — but the uninitialized bytes are
still embedded in the font buffer.
No sandbox contains this: OTS is NOT among the wasm-sandboxed libraries
(toolkit/moz.configure:2832-2840 lists graphite, ogg, hunspell, expat, woff2,
soundtouch). gfxOTSUtils.h is Mozilla's own code running in-process.
CONFIDENCE: high on links 1-3, read verbatim, and a defect regardless of the
rest; medium on links 4-5 and on the full chain, which I did not assemble.
Expected results:
The sanitizer output buffer should never contain bytes the sanitizer did not
write.
Suggested fixes — either breaks the chain, both are worth doing:
- zero the skipped region in gfxOTSExpandingMemoryStream::Seek, or allocate
the buffer with calloc;
- clamp MapCharToGlyphFormat4's limit to the subtable's own length rather
than the remainder of the cmap table.
To confirm: build with MSan or a junk-filling mozjemalloc, load the font, and
check whether measureText("\uFFFF").width corresponds to glyph 0xE5E5+2.
Reported for the Mozilla bug bounty. Source review only, not executed on a
running build; the font binary was not assembled.
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
Likely the expanding memory stream's Seek does not zero-fill skipped bytes, and the cmap glyph lookup uses the whole table length as its bound instead of the subtable length.
Impact
An attacker could disclose roughly two attacker-chosen bytes of heap memory per lookup, repeatable within an attacker-sized window, on Windows and macOS; on Linux and Android the uninitialized bytes remain in the font buffer but the lookup path does not apply.
What the attacker needed
Victim loads a page with a crafted font; Windows or macOS Firefox; script runs on the page
The fix
The skipped region should be zeroed in the expanding memory stream's Seek or the buffer allocated with calloc, and the cmap glyph lookup limit should be clamped to the subtable's own length.
How it was found
- Serve a WOFF/OTF font via @font-face with a cmap containing two encoding records.
- The first record is a format 4 subtable with an odd idRangeOffset on the last segment.
- The second record is a format 14 subtable with a large non-default UVS offset.
- Call ctx.measureText on the character U+FFFF from page script.
- Observe that the measured advance corresponds to a glyph ID read from uninitialized heap.
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.
When a browser loads a web font, it first checks and rewrites the font data with a sanitiser. This report says the sanitiser's buffer can contain leftover memory from other programs if the font makes it skip ahead without writing. A malicious font could then make the browser read those leftover bytes and reveal them through text measurements.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.