r19671 by jghali - #12827: crash on pdf export
scribus-commit
scribus-commit at lists.scribus.net
Thu Dec 18 23:19:04 UTC 2014
Author: jghali
Date: Thu Dec 18 23:19:04 2014
New Revision: 19671
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19671
Log:
#12827: crash on pdf export
Modified:
trunk/Scribus/scribus/pdf_analyzer.cpp
trunk/Scribus/scribus/pdflib_core.cpp
Modified: trunk/Scribus/scribus/pdf_analyzer.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19671&path=/trunk/Scribus/scribus/pdf_analyzer.cpp
==============================================================================
--- trunk/Scribus/scribus/pdf_analyzer.cpp (original)
+++ trunk/Scribus/scribus/pdf_analyzer.cpp Thu Dec 18 23:19:04 2014
@@ -74,6 +74,8 @@
nameMapInited = true;
}
+ m_doc = 0;
+
PdfError::EnableDebug( false );
try {
m_doc = new PdfMemDocument(filename.toLocal8Bit().data());
@@ -88,11 +90,14 @@
PDFAnalyzer::~PDFAnalyzer()
{
- delete m_doc;
+ if (m_doc)
+ delete m_doc;
}
bool PDFAnalyzer::inspectPDF(int pageNum, QList<PDFColorSpace> & usedColorSpaces, bool & hasTransparency, QList<PDFFont> & usedFonts, QList<PDFImage> & imgs)
{
+ if (!m_doc)
+ return false;
PdfPage* page = m_doc->GetPage(pageNum);
return page?inspectCanvas(page, usedColorSpaces, hasTransparency, usedFonts, imgs):false;
}
Modified: trunk/Scribus/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19671&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp (original)
+++ trunk/Scribus/scribus/pdflib_core.cpp Thu Dec 18 23:19:04 2014
@@ -49,6 +49,7 @@
#include <QPixmap>
#include <QRect>
#include <QRegExp>
+#include <QScopedPointer>
#include <QStack>
#include <QString>
#include <QTemporaryFile>
@@ -9754,13 +9755,27 @@
if (!Options.embedPDF)
return false;
+
#ifdef HAVE_PODOFO
+ // Try to catch potential pdf parsing exceptions early
+ // so we can use the raster fallback if needed
+ QScopedPointer<PoDoFo::PdfMemDocument> doc;
try
{
PoDoFo::PdfError::EnableDebug( false );
PoDoFo::PdfError::EnableLogging( false );
- PoDoFo::PdfMemDocument doc( fn.toLocal8Bit().data() );
- PoDoFo::PdfPage* page = doc.GetPage(qMin(qMax(1, c->pixm.imgInfo.actualPageNumber), c->pixm.imgInfo.numberOfPages) - 1);
+ doc.reset(new PoDoFo::PdfMemDocument(fn.toLocal8Bit().data()));
+ }
+ catch(PoDoFo::PdfError& e)
+ {
+ qDebug() << "PoDoFo error, falling back to raster!";
+ e.PrintErrorMsg();
+ return false;
+ }
+
+ try
+ {
+ PoDoFo::PdfPage* page = doc->GetPage(qMin(qMax(1, c->pixm.imgInfo.actualPageNumber), c->pixm.imgInfo.numberOfPages) - 1);
PoDoFo::PdfObject* contents = page? page->GetContents() : NULL;
PoDoFo::PdfObject* resources = page? page->GetResources() : NULL;
for (PoDoFo::PdfObject* par = page->GetObject(); par && !resources; par = par->GetIndirectKey("Parent"))
@@ -9823,7 +9838,7 @@
char * mbuffer = NULL;
long mlen = 0;
-#if ( (PODOFO_VERSION_MAJOR == 0) && (PODOFO_VERSION_MINOR == 7) && (PODOFO_VERSION_PATCH == 99) ) || ( (PODOFO_VERSION_MAJOR == 0) && (PODOFO_VERSION_MINOR > 7) )
+#if (PODOFO_VERSION >= PODOFO_MAKE_VERSION(0, 7, 99))
// seems more complicated at first, but in fact it makes the code more stable wrt podofo changes
PoDoFo::PdfMemoryOutputStream oStream(1);
stream->GetCopy(&oStream);
@@ -9951,14 +9966,14 @@
else if(carray[ci].IsReference())
{
- nextObj = doc.GetObjects().GetObject(carray[ci].GetReference());
+ nextObj = doc->GetObjects().GetObject(carray[ci].GetReference());
while(nextObj != NULL)
{
if(nextObj->IsReference())
{
- nextObj = doc.GetObjects().GetObject(nextObj->GetReference());
+ nextObj = doc->GetObjects().GetObject(nextObj->GetReference());
}
else if(nextObj->HasStream())
{
@@ -10115,7 +10130,7 @@
char * mbuffer = NULL;
long mlen = 0;
-#if ( (PODOFO_VERSION_MAJOR == 0) && (PODOFO_VERSION_MINOR == 7) && (PODOFO_VERSION_PATCH == 99) ) || ( (PODOFO_VERSION_MAJOR == 0) && (PODOFO_VERSION_MINOR > 7) )
+#if (PODOFO_VERSION >= PODOFO_MAKE_VERSION(0, 7, 99))
// seems more complicated at first, but in fact it makes the code more stable wrt podofo changes
PoDoFo::PdfMemoryOutputStream oStream(1);
stream->GetCopy(&oStream);
More information about the scribus-commit
mailing list