[r1996] SEGV of podofotxtextract in Type0 font handling (by...
A PDF parsing, modification and creation library.
Brought to you by:
domseichter
Hi,
Our fuzzer found a crash on podofotxtextract (the latest commit on trunk r1996 - version 0.9.6) due to an invalid read of size 1 on function PoDoFo::PdfFontFactory::CreateFont.
PoC: https://github.com/strongcourage/PoCs/blob/master/podofo_r1996/PoC_segv_PoDoFo::PdfVariant::DelayedLoad
Command: podofotxtextract $PoC
ASAN says:
==14022==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000013 (pc 0x0000004bc1ac sp 0x7ffca35cc920 bp 0x7ffca35cc930 T0)
#0 0x4bc1ab in PoDoFo::PdfVariant::DelayedLoad() const /home/dungnguyen/gueb-testing/podofo-code/podofo/trunk/src/podofo/base/PdfVariant.h:555
#1 0x4bc623 in PoDoFo::PdfVariant::GetArray() /home/dungnguyen/gueb-testing/podofo-code/podofo/trunk/src/podofo/base/PdfVariant.h:822
#2 0x51e48e in PoDoFo::PdfFontFactory::CreateFont(FT_LibraryRec_**, PoDoFo::PdfObject*) /home/dungnguyen/gueb-testing/podofo-code/podofo/trunk/src/podofo/doc/PdfFontFactory.cpp:218
#3 0x5152b7 in PoDoFo::PdfFontCache::GetFont(PoDoFo::PdfObject*) /home/dungnguyen/gueb-testing/podofo-code/podofo/trunk/src/podofo/doc/PdfFontCache.cpp:362
#4 0x53be5c in PoDoFo::PdfMemDocument::GetFont(PoDoFo::PdfObject*) /home/dungnguyen/gueb-testing/podofo-code/podofo/trunk/src/podofo/doc/PdfMemDocument.cpp:703
#5 0x4ba64a in TextExtractor::ExtractText(PoDoFo::PdfMemDocument*, PoDoFo::PdfPage*) /home/dungnguyen/gueb-testing/podofo-code/podofo/trunk/tools/podofotxtextract/TextExtractor.cpp:124
#6 0x4b9fe7 in TextExtractor::Init(char const*) /home/dungnguyen/gueb-testing/podofo-code/podofo/trunk/tools/podofotxtextract/TextExtractor.cpp:50
#7 0x4c00b9 in main /home/dungnguyen/gueb-testing/podofo-code/podofo/trunk/tools/podofotxtextract/podofotxtextract.cpp:52
#8 0x7f8d9f7d282f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#9 0x4b9ce8 in _start (/home/dungnguyen/PoCs/podofo_r1996/podofotxtextract-asan+0x4b9ce8)
Valgrind says:
==14548== Invalid read of size 1
==14548== at 0x564763: DelayedLoad (PdfVariant.h:555)
==14548== by 0x564763: GetArray (PdfVariant.h:822)
==14548== by 0x564763: PoDoFo::PdfFontFactory::CreateFont(FT_LibraryRec_**, PoDoFo::PdfObject*) (PdfFontFactory.cpp:218)
==14548== by 0x557B44: PoDoFo::PdfFontCache::GetFont(PoDoFo::PdfObject*) (PdfFontCache.cpp:362)
==14548== by 0x445D10: TextExtractor::ExtractText(PoDoFo::PdfMemDocument*, PoDoFo::PdfPage*) (TextExtractor.cpp:124)
==14548== by 0x44AB33: TextExtractor::Init(char const*) (TextExtractor.cpp:50)
==14548== by 0x43C837: main (podofotxtextract.cpp:52)
==14548== Address 0x13 is not stack'd, malloc'd or (recently) free'd
Thanks,
Manh Dung
Related
Commit: [r1996]
I'll fix this also ASAP (hopefully today), I think this is a different logical change from the fix for issue #57.
Please refrain from creating issues for crashes with PdfFontFactory in the backtrace for now, especially for PdfFontFactory.cpp (svn r1997) lines 195 and 229, which I already know about (from reading the source code). I haven't committed fixes for them with the fix for this issue, because IMHO those are different logical changes, and I'd like to do one commit for each of them.
I've committed my fix now into svn r1997, setting this to "pending" to say I'm done with my testing & committing, but for it to be "fixed" I'd like others to also test, especially on platforms they happen to use, but I don't (e.g. Windows).
Thanks Matthew. It works.
As you suggested, I provide a new crashing input due to a heap buffer overflow bug on the commit r1997. Note that the stacktrace contains the function PoDoFo::PdfFontFactory::CreateFont (line 241). Therefore, when you finish your fix, you could also test podofotxtextract with this crashing input.
PoC: https://github.com/strongcourage/PoCs/blob/master/podofo_r1997/PoC_hbo_PdfFontMetricsObject
Command: podofotxtextract $PoC
Valgrind says:
Thanks,
Manh Dung
[r1997] One more crashing input in PdfFontFactory::CreateFont (line 229) for testing your patch.
PoC: https://github.com/strongcourage/PoCs/blob/master/podofo_r1997/PoC_segv_GetIndirectKey
ASAN says:
Related
Commit: [r1997]
Thank you for your PoC and backtrace, also for those in your post before to this issue, they're valuable for reproducing the bugs, which I'd like to fix after issue #60 (which has been reported on the mailing list over 3 years ago and isn't really fixed yet AFAIK). However they're really distinct bugs, so should go into new issues again now (can you move them or should I ?)
Thanks Matthew. Which bugs should I create new issues ? Or both of them?
For both of them, please.