flexpaper / pdf2json

PDF2JSON is a conversion library based on XPDF (3.02) which can be used for high performance PDF page by page conversion to JSON and XML format. It also supports compressing data to minimize size. PDF2JSON is available for Windows, OSX and Linux. Please see https://flowpaper.com for more information
305 stars 52 forks source link

Detected memory leaks #21

Open fouzhe opened 6 years ago

fouzhe commented 6 years ago

I use Clang 6.0 and AddressSanitizer to build pdf2json v0.69, this file can cause memory leaks with the following command:

./pdf2json detected_memory_leaks.pdf 1.json

This is the ASAN information:

=================================================================
==15578==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x516e58 in operator new(unsigned long) /home/fouzhe/llvm/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:92
    #1 0x5e9bcf in GString::copy() /home/fouzhe/my_fuzz/pdf2json/xpdf/./../goo/GString.h:41:28
    #2 0x5e9bcf in GlobalParams::getTextEncodingName() /home/fouzhe/my_fuzz/pdf2json/xpdf/GlobalParams.cc:2256

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x516e58 in operator new(unsigned long) /home/fouzhe/llvm/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:92
    #1 0x6094f1 in Page::getLinks(Catalog*) /home/fouzhe/my_fuzz/pdf2json/xpdf/Page.cc:254:11
    #2 0x60fe2e in PDFDoc::getLinks(int) /home/fouzhe/my_fuzz/pdf2json/xpdf/PDFDoc.cc:351:34
    #3 0x60fe2e in PDFDoc::displayPage(OutputDev*, int, double, double, int, int, int, int, int (*)(void*), void*) /home/fouzhe/my_fuzz/pdf2json/xpdf/PDFDoc.cc:320
    #4 0x60fe2e in PDFDoc::displayPages(OutputDev*, int, int, double, double, int, int, int, int, int (*)(void*), void*) /home/fouzhe/my_fuzz/pdf2json/xpdf/PDFDoc.cc:332

Indirect leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x517008 in operator new[](unsigned long) /home/fouzhe/llvm/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:95
    #1 0x8cc5ce in GString::resize(int) /home/fouzhe/my_fuzz/pdf2json/goo/GString.cc:87:9
    #2 0x8cc5ce in GString::GString(GString*) /home/fouzhe/my_fuzz/pdf2json/goo/GString.cc:131

SUMMARY: AddressSanitizer: 40 byte(s) leaked in 3 allocation(s).