r24375 by jghali - Fix potential crash when importing PDF if user enters a wrong page selection

scribus-commit scribus-commit at lists.scribus.net
Mon Jan 4 22:48:30 UTC 2021


Author: jghali
Date: Mon Jan  4 22:48:29 2021
New Revision: 24375

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24375
Log:
Fix potential crash when importing PDF if user enters a wrong page selection

Modified:
    trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
    trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.cpp
    trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.h
    trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.ui

Modified: trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24375&path=/trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp	Mon Jan  4 22:48:29 2021
@@ -469,9 +469,13 @@
 					if (progressDialog)
 						progressDialog->show();
 				}
+
 				parsePagesString(pageString, &pageNs, lastPage);
+				if (pageNs.size() <= 0)
+					return false;
+
 				firstPage = pageNs[0];
-				SlaOutputDev* dev = {};
+				SlaOutputDev* dev = nullptr;
 				if (importTextAsVectors)
 					dev = new SlaOutputDev(m_Doc, &Elements, &importedColors, importerFlags);
 				else

Modified: trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24375&path=/trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.cpp	Mon Jan  4 22:48:29 2021
@@ -6,10 +6,13 @@
 */
 #include "pdfimportoptions.h"
 #include "ui_pdfimportoptions.h"
+
+#include "iconmanager.h"
 #include "importpdf.h"
 #include "ui/createrange.h"
+#include "ui/scmessagebox.h"
 #include "usertaskstructs.h"
-#include "iconmanager.h"
+#include "util.h"
 
 PdfImportOptions::PdfImportOptions(QWidget *parent) : QDialog(parent), ui(new Ui::PdfImportOptions)
 {
@@ -18,11 +21,41 @@
 	m_plugin = nullptr;
 	m_maxPage = 0;
 	m_resized = false;
+
+	connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onOkButtonClicked()));
+	connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
 }
 
 PdfImportOptions::~PdfImportOptions()
 {
 	delete ui;
+}
+
+void PdfImportOptions::onOkButtonClicked()
+{
+	// Check the page ranges
+	bool hasInvalidPageRange = false;
+	QString pageString(this->getPagesString());
+	std::vector<int> pageNumbers;
+
+	parsePagesString(pageString, &pageNumbers, m_maxPage);
+	for (size_t i = 0; i < pageNumbers.size(); ++i)
+	{
+		int pageNumber = pageNumbers[i];
+		if (pageNumber < 1 || pageNumber > m_maxPage)
+		{
+			hasInvalidPageRange = true;
+			break;
+		}
+	}
+
+	if ((pageNumbers.empty()) || hasInvalidPageRange)
+	{
+		ScMessageBox::warning(this, CommonStrings::trWarning, tr("The range of pages to import is invalid.\nPlease check it and try again."));
+		return;
+	}
+
+	accept();
 }
 
 void PdfImportOptions::resizeEvent(QResizeEvent *e)

Modified: trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24375&path=/trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.h
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.h	(original)
+++ trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.h	Mon Jan  4 22:48:29 2021
@@ -43,6 +43,9 @@
 	PdfPlug* m_plugin;
 	int m_maxPage;
 	bool m_resized;
+
+private slots:
+	void onOkButtonClicked();
 };
 
 #endif // PDFIMPORTOPTIONS_H

Modified: trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.ui
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24375&path=/trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.ui
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.ui	(original)
+++ trunk/Scribus/scribus/plugins/import/pdf/pdfimportoptions.ui	Mon Jan  4 22:48:29 2021
@@ -325,38 +325,6 @@
  <resources/>
  <connections>
   <connection>
-   <sender>buttonBox</sender>
-   <signal>accepted()</signal>
-   <receiver>PdfImportOptions</receiver>
-   <slot>accept()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>257</x>
-     <y>414</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>157</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>rejected()</signal>
-   <receiver>PdfImportOptions</receiver>
-   <slot>reject()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>325</x>
-     <y>414</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>286</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
    <sender>singlePage</sender>
    <signal>toggled(bool)</signal>
    <receiver>spinBox</receiver>




More information about the scribus-commit mailing list