r24498 by jghali - #16475: Error when trying to open document with size above 2Gb

scribus-commit scribus-commit at lists.scribus.net
Wed Feb 17 18:15:58 UTC 2021


Author: jghali
Date: Wed Feb 17 18:15:58 2021
New Revision: 24498

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24498
Log:
#16475: Error when trying to open document with size above 2Gb

Modified:
    trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
    trunk/Scribus/scribus/util.cpp
    trunk/Scribus/scribus/util.h

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24498&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp	(original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp	Wed Feb 17 18:15:58 2021
@@ -133,7 +133,7 @@
 	else
 	{
 		// Not gzip encoded, just load it
-		loadRawText(fileName, docBytes);
+		loadRawBytes(fileName, docBytes, 1024);
 	}
 
 	QRegExp regExp134("Version=\"1.3.[4-9]");

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24498&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp	Wed Feb 17 18:15:58 2021
@@ -139,7 +139,7 @@
 	else
 	{
 		// Not gzip encoded, just load it
-		loadRawText(fileName, docBytes);
+		loadRawBytes(fileName, docBytes, 1024);
 	}
 
 	QRegExp regExp150("Version=\"1.5.[0-9]");
@@ -962,19 +962,17 @@
 	QStack<int> groupStackMI2;
 	QStack<int> groupStackPI2;
 
-	QByteArray docBytes("");
-	loadRawText(fileName, docBytes);
-	QString f = QString::fromUtf8(docBytes);
-	if (f.isEmpty())
+	QScopedPointer<QIODevice> ioDevice(slaReader(fileName));
+	if (ioDevice.isNull())
 	{
 		setFileReadError();
 		return false;
 	}
 	QString fileDir = QFileInfo(fileName).absolutePath();
 
-	if (m_mwProgressBar!=nullptr)
-	{
-		m_mwProgressBar->setMaximum(f.length());
+	if (m_mwProgressBar != nullptr)
+	{
+		m_mwProgressBar->setMaximum(ioDevice->size());
 		m_mwProgressBar->setValue(0);
 	}
 
@@ -1009,7 +1007,7 @@
 	readObjectParams.itemKind = PageItem::StandardItem;
 	readObjectParams.loadingPage = false;
 
-	ScXmlStreamReader reader(f);
+	ScXmlStreamReader reader(ioDevice.data());
 	ScXmlStreamAttributes attrs;
 	while (!reader.atEnd() && !reader.hasError())
 	{
@@ -1021,7 +1019,7 @@
 
 		if (m_mwProgressBar != nullptr)
 		{
-			int newProgress = qRound(reader.characterOffset() / (double) f.length() * 100);
+			int newProgress = qRound(ioDevice->pos() / (double) ioDevice->size() * 100);
 			if (newProgress != progress)
 			{
 				m_mwProgressBar->setValue(reader.characterOffset());
@@ -1553,7 +1551,7 @@
 	int firstPage = 0;
 	int layerToSetActive = 0;
 	
-	if (m_mwProgressBar!=nullptr)
+	if (m_mwProgressBar != nullptr)
 	{
 		m_mwProgressBar->setMaximum(ioDevice->size());
 		m_mwProgressBar->setValue(0);

Modified: trunk/Scribus/scribus/util.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24498&path=/trunk/Scribus/scribus/util.cpp
==============================================================================
--- trunk/Scribus/scribus/util.cpp	(original)
+++ trunk/Scribus/scribus/util.cpp	Wed Feb 17 18:15:58 2021
@@ -170,8 +170,7 @@
 		QByteArray tempBuf(f.size() /*+ 1*/, ' ');
 		if (f.open(QIODevice::ReadOnly))
 		{
-			unsigned int bytesRead = f.read(tempBuf.data(), f.size());
-			/*tempBuf[bytesRead] = '\0';*/
+			qint64 bytesRead = f.read(tempBuf.data(), f.size());
 			ret = bytesRead == f.size();
 			if (ret)
 				buf = tempBuf; // sharing makes this efficient
@@ -192,7 +191,7 @@
 		QByteArray tempBuf(f.size(), ' ');
 		if (f.open(QIODevice::ReadOnly))
 		{
-			unsigned int bytesRead = f.read(tempBuf.data(), f.size());
+			qint64 bytesRead = f.read(tempBuf.data(), f.size());
 			ret = bytesRead == f.size();
 			if (ret)
 				buf = tempBuf; // sharing makes this efficient
@@ -203,6 +202,32 @@
 	return ret;
 }
 
+bool loadRawBytes(const QString & filename, QByteArray & buf, int maxLength)
+{
+	if (maxLength < 0)
+		return false;
+	bool ret = false;
+
+	QFile f(filename);
+	QFileInfo fi(f);
+	if (fi.exists())
+	{
+		QByteArray tempBuf(maxLength, ' ');
+		if (f.open(QIODevice::ReadOnly))
+		{
+			qint64 bytesRead = f.read(tempBuf.data(), (qint64) maxLength);
+			ret = (bytesRead > 0);
+			if (ret)
+			{
+				tempBuf.resize((int) bytesRead);
+				buf = tempBuf; // sharing makes this efficient
+			}
+		}
+	}
+	if (f.isOpen())
+		f.close();
+	return ret;
+}
 
 QString CompressStr(QString *in)
 {

Modified: trunk/Scribus/scribus/util.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24498&path=/trunk/Scribus/scribus/util.h
==============================================================================
--- trunk/Scribus/scribus/util.h	(original)
+++ trunk/Scribus/scribus/util.h	Wed Feb 17 18:15:58 2021
@@ -71,6 +71,7 @@
 old contents. */
 bool SCRIBUS_API loadRawText(const QString & filename, QByteArray & buf);
 bool SCRIBUS_API loadRawBytes(const QString & filename, QByteArray & buf);
+bool SCRIBUS_API loadRawBytes(const QString & filename, QByteArray & buf, int maxLength);
 /**
 * @brief Synchronously execute a new process, optionally saving its output
    *




More information about the scribus-commit mailing list