AddressSanitizer: heap-buffer-overflow READ of size 2 graphite2
A crafted TrueType font file causes the graphite2 font shaping library to read two bytes past the end of a heap allocation while running its bytecode interpreter. The reporter asks whether Firefox, which uses graphite2, is affected; the text does not show any browser exploitation.
Originally disclosed on Mozilla
- Fixed in 23 days
- Paid in 29 days
- Disclosed after 23 days
Created attachment 9081158 graphite2.ttf
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36
Steps to reproduce:
Can you check if Firefox is affected?
./gr2fonttest graphite2.ttf -auto
Actual results:
=================================================================
==13801==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000002a8 at pc 0x7fdde25ab64a bp 0x7ffc4196e2a0 sp 0x7ffc4196e290
READ of size 2 at 0x6020000002a8 thread T0
#0 0x7fdde25ab649 in (anonymous namespace)::direct_run(bool, void* const*, unsigned char const*, int*, graphite2::Slot**&, unsigned char, graphite2::vm::Machine::status_t&, graphite2::SlotMap*) (/home/rs/dev/graphite/build/src/libgraphite2.so.3+0x5649)
#1 0x7fdde25aab08 in graphite2::vm::Machine::run(void* const*, unsigned char const*, graphite2::Slot**&) (/home/rs/dev/graphite/build/src/libgraphite2.so.3+0x4b08)
#2 0x7fdde25f09d6 in graphite2::Pass::findNDoRule(graphite2::Slot*&, graphite2::vm::Machine&, graphite2::FiniteStateMachine&) const (/home/rs/dev/graphite/build/src/libgraphite2.so.3+0x4a9d6)
#3 0x7fdde25f6371 in graphite2::Pass::runGraphite(graphite2::vm::Machine&, graphite2::FiniteStateMachine&, bool) const (/home/rs/dev/graphite/build/src/libgraphite2.so.3+0x50371)
#4 0x7fdde26033a6 in graphite2::Silf::runGraphite(graphite2::Segment*, unsigned char, unsigned char, int) const (/home/rs/dev/graphite/build/src/libgraphite2.so.3+0x5d3a6)
#5 0x7fdde25d4a19 in graphite2::Face::runGraphite(graphite2::Segment*, graphite2::Silf const*) const (/home/rs/dev/graphite/build/src/libgraphite2.so.3+0x2ea19)
#6 0x7fdde25b36d0 in gr_make_seg (/home/rs/dev/graphite/build/src/libgraphite2.so.3+0xd6d0)
#7 0x55b328a62642 in Parameters::testFileFont() const (/home/rs/dev/graphite/build/gr2fonttest/gr2fonttest+0x6642)
#8 0x55b328a60640 in main (/home/rs/dev/graphite/build/gr2fonttest/gr2fonttest+0x4640)
#9 0x7fdde20b1eca in __libc_start_main (/lib64/libc.so.6+0x23eca)
#10 0x55b328a60c19 in _start (/home/rs/dev/graphite/build/gr2fonttest/gr2fonttest+0x4c19)
0x6020000002a8 is located 16 bytes to the right of 8-byte region [0x602000000290,0x602000000298)
allocated by thread T0 here:
#0 0x7fdde270bbf0 in __interceptor_realloc /var/tmp/portage/sys-devel/gcc-8.3.0-r1/work/gcc-8.3.0/libsanitizer/asan/asan_malloc_linux.cc:105
#1 0x7fdde25f911d in graphite2::Segment::newSlot() [clone .part.71] (/home/rs/dev/graphite/build/src/libgraphite2.so.3+0x5311d)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/rs/dev/graphite/build/src/libgraphite2.so.3+0x5649) in (anonymous namespace)::direct_run(bool, void* const*, unsigned char const*, int*, graphite2::Slot**&, unsigned char, graphite2::vm::Machine::status_t&, graphite2::SlotMap*)
Shadow bytes around the buggy address:
0x0c047fff8000: fa fa 00 04 fa fa fd fd fa fa 00 02 fa fa 00 02
0x0c047fff8010: fa fa 00 02 fa fa 00 02 fa fa fd fa fa fa 00 00
0x0c047fff8020: fa fa 01 fa fa fa 00 04 fa fa 04 fa fa fa 00 00
0x0c047fff8030: fa fa 00 00 fa fa 04 fa fa fa 00 04 fa fa 00 fa
0x0c047fff8040: fa fa 02 fa fa fa 00 fa fa fa 01 fa fa fa 00 fa
=>0x0c047fff8050: fa fa 00 fa fa[fa]fa fa fa fa fa fa fa fa fa fa
0x0c047fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff80a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==13801==ABORTING
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 graphite2 virtual machine's direct_run routine reads a 16-bit value from a slot without checking that the slot has enough bytes allocated.
Impact
A malformed font could cause an out-of-bounds read in graphite2; the report does not demonstrate a crash or code execution in Firefox itself.
What the attacker needed
A crafted font file; software using graphite2 to render it
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.
Fonts can contain small programs that tell the computer how to draw letters. A bug in the library that runs these programs (graphite2) lets a malformed font make it read memory it should not touch. The report only shows this happening in a command-line test tool, not in a browser.
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.