silnrsi / graphite

Graphite is a "smart font" system developed specifically to handle the complexities of lesser-known languages of the world.
http://graphite.sil.org/
Other
147 stars 44 forks source link

segfault in libgraphite2 graphite2::Segment::removeScope() #28

Closed gsharpsh00ter closed 6 years ago

gsharpsh00ter commented 6 years ago

0x01 Description

In libgraphite2 version 1.3.11 and the master branch, a segment fault vulnerability was found in graphite2::Segment::removeScope(), which may allow attackers to cause a denial of service or possibly other impact via a crafted font type file.

0x02 How to reproduce

This issue can be reproduced by the following command: gr2fonttest $POC -rtl -j 30 -cache -bytes 1 -noprint -codes 1000 102f 103f 104f 105f 106f 107f 108f 109f 10af 10bf 10cf 10df 10ef 10ff 2000 2001 2002 2003

0x03 Debugging Information

gzq@ubuntu:~/tmp/graphite/build/gr2fonttest$ gdb -q ./gr2fonttest
Reading symbols from ./gr2fonttest...done.
(gdb) r libgraphite2-segfault-graphite2::Segment::removeScope-1.ttf -rtl -j 30 -cache -bytes 1 -noprint -codes 1000 102f 103f 104f 105f 106f 107f 108f 109f 10af 10bf 10cf 10df 10ef 10ff 2000 2001 2002 2003
Starting program: /home/gzq/tmp/graphite/build/gr2fonttest/gr2fonttest libgraphite2-segfault-graphite2::Segment::removeScope-1.ttf -rtl -j 30 -cache -bytes 1 -noprint -codes 1000 102f 103f 104f 105f 106f 107f 108f 109f 10af 10bf 10cf 10df 10ef 10ff 2000 2001 2002 2003
Text codes
1000    102f    103f    104f    105f    106f    107f    108f    109f    10af
10bf    10cf    10df    10ef    10ff    2000    2001    2002    2003    

Program received signal SIGSEGV, Segmentation fault.
graphite2::Segment::removeScope (this=this@entry=0x555555780100, state=...) at /home/gzq/tmp/graphite/src/Segment.cpp:105
105         m_first->prev(state.slotBeforeScope);
(gdb) print m_first
$1 = (graphite2::Slot *) 0x0
(gdb) bt
#0  graphite2::Segment::removeScope (this=this@entry=0x555555780100, state=...) at /home/gzq/tmp/graphite/src/Segment.cpp:105
#1  0x00007ffff7babb95 in graphite2::CachedFace::runGraphite (this=0x55555576d4b0, seg=<optimized out>, pSilf=<optimized out>) at /home/gzq/tmp/graphite/src/CachedFace.cpp:109
#2  0x00007ffff7bab213 in graphite2::Segment::runGraphite (this=0x555555780100) at /home/gzq/tmp/graphite/src/inc/Segment.h:97
#3  (anonymous namespace)::makeAndInitialize (dir=1, nChars=19, pStart=0x555555771570, enc=gr_utf8, pFeats=0x5555557800a0, script=0, face=0x55555576d4b0, font=0x555555771520) at /home/gzq/tmp/graphite/src/gr_segment.cpp:46
#4  gr_make_seg (font=0x555555771520, face=0x55555576d4b0, script=<optimized out>, pFeats=0x5555557800a0, enc=gr_utf8, pStart=0x555555771570, nChars=19, dir=1) at /home/gzq/tmp/graphite/src/gr_segment.cpp:105
#5  0x0000555555557109 in Parameters::testFileFont (this=0x7fffffffe210) at /home/gzq/tmp/graphite/gr2fonttest/gr2FontTest.cpp:700
#6  0x0000555555555f98 in main (argc=29, argv=0x7fffffffe388) at /home/gzq/tmp/graphite/gr2fonttest/gr2FontTest.cpp:810
(gdb) 

For security consideration, the poc file attached is encrypted with a password which I have sent to you.

0x04 Author

This issue is reported by Ziqiang Gu from WeiRan Labs.

0x05 POC

libgraphite2-segfault-graphite2SegmentremoveScope-1.zip

mhosken commented 6 years ago

The segcache has been removed, thus -cache is no longer valid. Please retest without -cache and reopen this bug if there is still a problem.