Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when PdfDictionary->Exists("Info") doesn't exist #158

Open
gnat42 opened this issue Jul 3, 2019 · 1 comment
Open

Crash when PdfDictionary->Exists("Info") doesn't exist #158

gnat42 opened this issue Jul 3, 2019 · 1 comment

Comments

@gnat42
Copy link

gnat42 commented Jul 3, 2019

We have a PDF that has no Info dictionary. Using the following code we get a crash when querying if the trailer has an info entry or not. The crash seems deep in the std::map::find code which is bizarre.

int main(int argc, const char * argv[]) {
    InputFile inFile;
    PDFParser parser;
    RefCountPtr<PDFDictionary> trailer;
    
    if (argc != 2) {
        std::cout << "Invalid number of arguments\n";
        return -1;
    }
    
    std::string inputFilePath(argv[1]);
    inFile.OpenFile(inputFilePath);
    parser.StartPDFParsing(inFile.GetInputStream());

    trailer = parser.GetTrailer();
    if (!trailer->Exists("Info")) {
        std::cout << "File has no info\n";
        return -1;
    }

    std::cout << "File has info\n";
    return 0;
}

The stack trace is as follows:

#0  0x00007f0aa67a5766 in std::_Rb_tree<PDFName*, std::pair<PDFName* const, PDFObject*>, std::_Select1st<std::pair<PDFName* const, PDFObject*> >, PDFNameLess, std::allocator<std::pair<PDFName* const, PDFObject*> > >::find (this=this@entry=0x48, __k=@0x7ffcebc672a8: 0x7ffcebc672b0)
    at /usr/include/c++/9/bits/stl_tree.h:766
#1  0x00007f0aa67a56c3 in std::map<PDFName*, PDFObject*, PDFNameLess, std::allocator<std::pair<PDFName* const, PDFObject*> > >::find (__x=@0x7ffcebc672a8: 0x7ffcebc672b0, this=0x48)
    at /usr/include/c++/9/bits/stl_map.h:1168
#2  PDFDictionary::Exists (this=this@entry=0x0, inName="Info")
    at /usr/src/debug/pdf-writer-4.0-1.fc30.x86_64/PDFWriter/PDFDictionary.cpp:66

Here's the super simple PDF:
2015-08-15-mypdf.pdf

Is there something that should be handle in this case? Is the issue in std::map, or PDFDictionary or should I be doing something different in our code?

@gnat42
Copy link
Author

gnat42 commented Jul 3, 2019

So I dug deeper and noticed that the ! operator overload so !trailer is true, you can see Exists(this=@entry=0x0, inName="Info") so it doesn't parse the trailer properly? Is this a bug in PDFWriter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant