Skip to content

Commit

Permalink
Fixed CVE-2019-9199, issue #40 (raises PdfError with PageNotFound cod…
Browse files Browse the repository at this point in the history
…e on error)

The error is the page 0 (0-based) not being found, before this fix that led to
a null pointer dereference (method call on a null pointer, undefined behavior),
now just a PdfError exception is raised.
  • Loading branch information
Beatriz Manrique committed Mar 9, 2019
1 parent 62132fb commit ada821d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tools/podofoimpose/pdftranslator.cpp
Expand Up @@ -148,7 +148,12 @@ namespace PoDoFo
// std::cerr << "Document has "<< pcount << " page(s) " << endl;
if ( pcount > 0 ) // only here to avoid possible segfault, but PDF without page is not conform IIRC
{
PoDoFo::PdfRect rect ( sourceDoc->GetPage ( 0 )->GetMediaBox() );
PoDoFo::PdfPage* pFirstPage = sourceDoc->GetPage ( 0 );
if ( NULL == pFirstPage ) // Fixes CVE-2019-9199 (issue #40)
{
PODOFO_RAISE_ERROR_INFO( ePdfError_PageNotFound, "First page (0) of source document not found" );
}
PoDoFo::PdfRect rect ( pFirstPage->GetMediaBox() );
// keep in mind it’s just a hint since PDF can have different page sizes in a same doc
sourceWidth = rect.GetWidth() - rect.GetLeft();
sourceHeight = rect.GetHeight() - rect.GetBottom() ;
Expand Down

0 comments on commit ada821d

Please sign in to comment.