Unchecked `fd = font->fdselect[gid]` used to index per-fontdict arrays in CFF subsetter
Categories
(Core :: Graphics: Text, defect)
Tracking
()
People
(Reporter: zzjas98, Unassigned)
References
Details
(Keywords: reporter-external, sec-low)
Attachments
(2 files)
Steps to reproduce:
With an ASan build of Firefox:
cp cairo-poc-fdselect-index.otf ~/.fontandfc-cache -f. This installs the malicious font.- Load
file:///path/to/fdselect-index.html - Print -> (Save as PDF) Save -> Save
Actual results:
Browser crashes with:
==900621==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x79e2c635d9f8 at pc 0x79c2ac05c18a bp 0x7ffd9acf3840 sp 0x7ffd9acf3838
READ of size 4 at 0x79e2c635d9f8 thread T0
#0 0x79c2ac05c189 in cairo_cff_parse_charstring .../firefox/gfx/cairo/cairo/src/cairo-cff-subset.c:1615:43
#1 0x79c2ac04ef23 in cairo_cff_find_width_and_subroutines_used .../firefox/gfx/cairo/cairo/src/cairo-cff-subset.c:1703:14
#2 0x79c2ac04ef23 in cairo_cff_font_subset_charstrings_and_subroutines .../firefox/gfx/cairo/cairo/src/cairo-cff-subset.c:1820:15
#3 0x79c2ac04ef23 in cairo_cff_font_subset_font .../firefox/gfx/cairo/cairo/src/cairo-cff-subset.c:2005:14
#4 0x79c2ac04ef23 in cairo_cff_font_generate .../firefox/gfx/cairo/cairo/src/cairo-cff-subset.c:2618:14
#5 0x79c2ac04ef23 in _cairo_cff_subset_init .../firefox/gfx/cairo/cairo/src/cairo-cff-subset.c:2995:14
#6 0x79c2ac0b42ef in _cairo_pdf_surface_emit_cff_font_subset .../firefox/gfx/cairo/cairo/src/cairo-pdf-surface.c:6249:14
#7 0x79c2ac0b42ef in _cairo_pdf_surface_emit_unscaled_font_subset .../firefox/gfx/cairo/cairo/src/cairo-pdf-surface.c:7141:14
#8 0x79c2ac1c580b in _cairo_sub_font_collect .../firefox/obj-ff-asan/gfx/cairo/cairo/src/./../../../../../gfx/cairo/cairo/src/cairo-scaled-font-subsets.c:733:30
#9 0x79c2ac1c580b in _cairo_scaled_font_subsets_foreach_internal .../firefox/obj-ff-asan/gfx/cairo/cairo/src/./../../../../../gfx/cairo/cairo/src/cairo-scaled-font-subsets.c:1068:2
#10 0x79c2ac09b760 in _cairo_pdf_surface_emit_font_subsets .../firefox/gfx/cairo/cairo/src/cairo-pdf-surface.c:7185:14
Expected results:
No OOB read.
Tested on commit 7c0714b51fe1.
Analysis
font->fdselect[] entries are bytes copied straight from the CFF FDSelect table (range 0..255), with no comparison against font->num_fontdicts:
Commit 3481ea88c7a8 added a range check, but only at one downstream site:
Two earlier sites in the same cairo_cff_font_subset_font flow read fd from fdselect and use it unguarded to index arrays sized by num_fontdicts:
Please let me know if I can provide any more information, thanks!
| Reporter | ||
Comment 1•6 months ago
|
||
Updated•6 months ago
|
Updated•6 months ago
|
Updated•6 months ago
|
Comment 2•6 months ago
|
||
Your steps to reproduce involve installing a system font. I assume that means that it doesn't get past OTS or whatever font sanitizer Firefox uses on web fonts?
Comment 3•6 months ago
|
||
The same considerations apply as in bug 2037290 comment 4:
The example font here is rejected by OTS if we attempt to load it as a webfont. Therefore, it could only reach the cairo subsetting code if installed locally by the user.
That's not to say we shouldn't harden the subsetting code, too, but given the requirement for both local font installation and executing a print operation, neither of which can be done directly by a website without user confirmation, the risk here seems relatively low.
| Reporter | ||
Comment 4•6 months ago
|
||
(In reply to Andrew McCreight [:mccr8] from comment #2)
Your steps to reproduce involve installing a system font. I assume that means that it doesn't get past OTS or whatever font sanitizer Firefox uses on web fonts?
Yes as Janothan mentioned, this cannot pass OTS so local installation is needed. I'll keep a note on this as I try to scan for more bugs. Thanks!
Updated•6 months ago
|
Comment 5•4 months ago
|
||
The rating assigned by our bug rating tool (currently under development) is:
Rating: sec-low
Explanation: This is a genuine heap-buffer-overflow (OOB read) in the cairo CFF font subsetter — fdselect[gid] values are used unguarded to index per-fontdict arrays at two call sites (lines 1633 and 1728), even though a bounds check was added at a third site (line 1901). However, the vulnerability is severely constrained: (1) the malicious font is rejected by OTS so it cannot be loaded as a web font — it must be installed as a system font by the user; (2) the vulnerable code only runs during a Print→Save as PDF operation. Neither condition can be met directly by a remote website without user action. The OOB is a read (not write), limiting exploitability to information disclosure rather than arbitrary code execution. These unusual preconditions place the issue in the sec-low range — clearly a security concern warranting a fix, but very limited in scope and not directly exploitable via normal browsing.
Please ni? me if you disagree with this rating.
Updated•3 months ago
|
Updated•1 month ago
|
Comment 7•10 days ago
|
||
Clearing the needinfo request since this bug is a duplicate of bug 2048801, which has been closed for 4 months and 5 days.
For more information, please visit BugBot documentation.
Description
•