summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/quazip
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/quazip')
-rw-r--r--rbutil/rbutilqt/quazip/README.ROCKBOX4
-rw-r--r--rbutil/rbutilqt/quazip/ioapi.h2
-rw-r--r--rbutil/rbutilqt/quazip/minizip_crypt.h (renamed from rbutil/rbutilqt/quazip/crypt.h)2
-rw-r--r--rbutil/rbutilqt/quazip/qioapi.cpp8
-rw-r--r--rbutil/rbutilqt/quazip/quazip.cpp96
-rw-r--r--rbutil/rbutilqt/quazip/quazip.h48
-rw-r--r--rbutil/rbutilqt/quazip/quazip.pri2
-rw-r--r--rbutil/rbutilqt/quazip/quazip_global.h8
-rw-r--r--rbutil/rbutilqt/quazip/quazipfile.cpp90
-rw-r--r--rbutil/rbutilqt/quazip/quazipfile.h54
-rw-r--r--rbutil/rbutilqt/quazip/quazipfileinfo.cpp146
-rw-r--r--rbutil/rbutilqt/quazip/quazipfileinfo.h54
-rw-r--r--rbutil/rbutilqt/quazip/quazipnewinfo.cpp23
-rw-r--r--rbutil/rbutilqt/quazip/quazipnewinfo.h13
-rw-r--r--rbutil/rbutilqt/quazip/unzip.c48
-rw-r--r--rbutil/rbutilqt/quazip/unzip.h5
-rw-r--r--rbutil/rbutilqt/quazip/zip.c46
-rw-r--r--rbutil/rbutilqt/quazip/zip.h3
18 files changed, 489 insertions, 163 deletions
diff --git a/rbutil/rbutilqt/quazip/README.ROCKBOX b/rbutil/rbutilqt/quazip/README.ROCKBOX
index b4ffc270ae..a168b2a079 100644
--- a/rbutil/rbutilqt/quazip/README.ROCKBOX
+++ b/rbutil/rbutilqt/quazip/README.ROCKBOX
@@ -3,7 +3,7 @@ These files are distributed under the LGPL v2.1 or later. Only source files
actually used in Rockbox Utility are included, further sources have been left
out. Check the quazip source distribution for those.
-The source files have been last synced with the projects release 0.7.1 at
-http://sourceforge.net/projects/quazip/ on March 8, 2015.
+The source files have been last synced with the projects release 0.9.1 at
+https://github.com/stachenov/quazip/ on June 8, 2020.
diff --git a/rbutil/rbutilqt/quazip/ioapi.h b/rbutil/rbutilqt/quazip/ioapi.h
index bbb94c8c76..75d0aa6933 100644
--- a/rbutil/rbutilqt/quazip/ioapi.h
+++ b/rbutil/rbutilqt/quazip/ioapi.h
@@ -44,7 +44,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include "zlib.h"
+#include <zlib.h>
#if defined(USE_FILE32API)
#define fopen64 fopen
diff --git a/rbutil/rbutilqt/quazip/crypt.h b/rbutil/rbutilqt/quazip/minizip_crypt.h
index ddee28e7dd..2e833f7f3c 100644
--- a/rbutil/rbutilqt/quazip/crypt.h
+++ b/rbutil/rbutilqt/quazip/minizip_crypt.h
@@ -34,7 +34,7 @@
/***********************************************************************
* Return the next byte in the pseudo-random sequence
*/
-static int decrypt_byte(unsigned long* pkeys, const z_crc_t FAR * pcrc_32_tab UNUSED)
+static int decrypt_byte(unsigned long* pkeys, const z_crc_t FAR * pcrc_32_tab QUAZIP_UNUSED)
{
//(void) pcrc_32_tab; /* avoid "unused parameter" warning */
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
diff --git a/rbutil/rbutilqt/quazip/qioapi.cpp b/rbutil/rbutilqt/quazip/qioapi.cpp
index 534dbdf51f..3932ebeef0 100644
--- a/rbutil/rbutilqt/quazip/qioapi.cpp
+++ b/rbutil/rbutilqt/quazip/qioapi.cpp
@@ -11,16 +11,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <zlib.h>
-#include "zlib.h"
#include "ioapi.h"
#include "quazip_global.h"
-#include <QIODevice>
+#include <QtCore/QIODevice>
#if (QT_VERSION >= 0x050100)
#define QUAZIP_QSAVEFILE_BUG_WORKAROUND
#endif
#ifdef QUAZIP_QSAVEFILE_BUG_WORKAROUND
-#include <QSaveFile>
+#include <QtCore/QSaveFile>
#endif
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
@@ -75,6 +75,7 @@ ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream
}
}
+/// @cond internal
struct QIODevice_descriptor {
// Position only used for writing to sequential devices.
qint64 pos;
@@ -82,6 +83,7 @@ struct QIODevice_descriptor {
pos(0)
{}
};
+/// @endcond
voidpf ZCALLBACK qiodevice_open_file_func (
voidpf opaque,
diff --git a/rbutil/rbutilqt/quazip/quazip.cpp b/rbutil/rbutilqt/quazip/quazip.cpp
index e3623c76e3..61c2ea87eb 100644
--- a/rbutil/rbutilqt/quazip/quazip.cpp
+++ b/rbutil/rbutilqt/quazip/quazip.cpp
@@ -22,12 +22,14 @@ Original ZIP package is copyrighted by Gilles Vollant, see
quazip/(un)zip.h files for details, basically it's zlib license.
**/
-#include <QFile>
-#include <QFlags>
-#include <QHash>
+#include <QtCore/QFile>
+#include <QtCore/QFlags>
+#include <QtCore/QHash>
#include "quazip.h"
+#define QUAZIP_OS_UNIX 3u
+
/// All the internal stuff for the QuaZip class.
/**
\internal
@@ -39,11 +41,12 @@ quazip/(un)zip.h files for details, basically it's zlib license.
class QuaZipPrivate {
friend class QuaZip;
private:
+ Q_DISABLE_COPY(QuaZipPrivate)
/// The pointer to the corresponding QuaZip instance.
QuaZip *q;
- /// The codec for file names.
+ /// The codec for file names (used when UTF-8 is not enabled).
QTextCodec *fileNameCodec;
- /// The codec for comments.
+ /// The codec for comments (used when UTF-8 is not enabled).
QTextCodec *commentCodec;
/// The archive file name.
QString zipName;
@@ -69,6 +72,10 @@ class QuaZipPrivate {
bool zip64;
/// The auto-close flag.
bool autoClose;
+ /// The UTF-8 flag.
+ bool utf8;
+ /// The OS code.
+ uint osCode;
inline QTextCodec *getDefaultFileNameCodec()
{
if (defaultFileNameCodec == NULL) {
@@ -88,8 +95,12 @@ class QuaZipPrivate {
zipError(UNZ_OK),
dataDescriptorWritingEnabled(true),
zip64(false),
- autoClose(true)
+ autoClose(true),
+ utf8(false),
+ osCode(defaultOsCode)
{
+ unzFile_f = NULL;
+ zipFile_f = NULL;
lastMappedDirectoryEntry.num_of_file = 0;
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
}
@@ -105,14 +116,18 @@ class QuaZipPrivate {
zipError(UNZ_OK),
dataDescriptorWritingEnabled(true),
zip64(false),
- autoClose(true)
+ autoClose(true),
+ utf8(false),
+ osCode(defaultOsCode)
{
+ unzFile_f = NULL;
+ zipFile_f = NULL;
lastMappedDirectoryEntry.num_of_file = 0;
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
}
/// The constructor for the corresponding QuaZip constructor.
inline QuaZipPrivate(QuaZip *q, QIODevice *ioDevice):
- q(q),
+ q(q),
fileNameCodec(getDefaultFileNameCodec()),
commentCodec(QTextCodec::codecForLocale()),
ioDevice(ioDevice),
@@ -121,8 +136,12 @@ class QuaZipPrivate {
zipError(UNZ_OK),
dataDescriptorWritingEnabled(true),
zip64(false),
- autoClose(true)
+ autoClose(true),
+ utf8(false),
+ osCode(defaultOsCode)
{
+ unzFile_f = NULL;
+ zipFile_f = NULL;
lastMappedDirectoryEntry.num_of_file = 0;
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
}
@@ -138,9 +157,11 @@ class QuaZipPrivate {
QHash<QString, unz64_file_pos> directoryCaseInsensitive;
unz64_file_pos lastMappedDirectoryEntry;
static QTextCodec *defaultFileNameCodec;
+ static uint defaultOsCode;
};
QTextCodec *QuaZipPrivate::defaultFileNameCodec = NULL;
+uint QuaZipPrivate::defaultOsCode = QUAZIP_OS_UNIX;
void QuaZipPrivate::clearDirectoryMap()
{
@@ -273,6 +294,8 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
flags |= ZIP_AUTO_CLOSE;
if (p->dataDescriptorWritingEnabled)
flags |= ZIP_WRITE_DATA_DESCRIPTOR;
+ if (p->utf8)
+ flags |= ZIP_ENCODING_UTF8;
p->zipFile_f=zipOpen3(ioDevice,
mode==mdCreate?APPEND_STATUS_CREATE:
mode==mdAppend?APPEND_STATUS_CREATEAFTER:
@@ -334,9 +357,9 @@ void QuaZip::close()
case mdCreate:
case mdAppend:
case mdAdd:
- p->zipError=zipClose(p->zipFile_f,
- p->comment.isNull() ? NULL
- : p->commentCodec->fromUnicode(p->comment).constData());
+ p->zipError=zipClose(p->zipFile_f, p->comment.isNull() ? NULL : isUtf8Enabled()
+ ? p->comment.toUtf8().constData()
+ : p->commentCodec->fromUnicode(p->comment).constData());
break;
default:
qWarning("QuaZip::close(): unknown mode: %d", (int)p->mode);
@@ -402,7 +425,9 @@ QString QuaZip::getComment()const
if((fakeThis->p->zipError=unzGetGlobalComment(p->unzFile_f, comment.data(), comment.size())) < 0)
return QString();
fakeThis->p->zipError = UNZ_OK;
- return p->commentCodec->toUnicode(comment);
+ unsigned flags = 0;
+ return (unzGetFileFlags(p->unzFile_f, &flags) == UNZ_OK) && (flags & UNZ_ENCODING_UTF8)
+ ? QString::fromUtf8(comment) : p->commentCodec->toUnicode(comment);
}
bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs)
@@ -537,8 +562,8 @@ bool QuaZip::getCurrentFileInfo(QuaZipFileInfo64 *info)const
info->diskNumberStart=info_z.disk_num_start;
info->internalAttr=info_z.internal_fa;
info->externalAttr=info_z.external_fa;
- info->name=p->fileNameCodec->toUnicode(fileName);
- info->comment=p->commentCodec->toUnicode(comment);
+ info->name=(info->flags & UNZ_ENCODING_UTF8) ? QString::fromUtf8(fileName) : p->fileNameCodec->toUnicode(fileName);
+ info->comment=(info->flags & UNZ_ENCODING_UTF8) ? QString::fromUtf8(comment) : p->commentCodec->toUnicode(comment);
info->extra=extra;
info->dateTime=QDateTime(
QDate(info_z.tmu_date.tm_year, info_z.tmu_date.tm_mon+1, info_z.tmu_date.tm_mday),
@@ -558,10 +583,13 @@ QString QuaZip::getCurrentFileName()const
}
if(!isOpen()||!hasCurrentFile()) return QString();
QByteArray fileName(MAX_FILE_NAME_LENGTH, 0);
- if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, NULL, fileName.data(), fileName.size(),
+ unz_file_info64 file_info;
+ if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &file_info, fileName.data(), fileName.size(),
NULL, 0, NULL, 0))!=UNZ_OK)
return QString();
- QString result = p->fileNameCodec->toUnicode(fileName.constData());
+ fileName.resize(file_info.size_filename);
+ QString result = (file_info.flag & UNZ_ENCODING_UTF8)
+ ? QString::fromUtf8(fileName) : p->fileNameCodec->toUnicode(fileName);
if (result.isEmpty())
return result;
// Add to directory map
@@ -576,7 +604,17 @@ void QuaZip::setFileNameCodec(QTextCodec *fileNameCodec)
void QuaZip::setFileNameCodec(const char *fileNameCodecName)
{
- p->fileNameCodec=QTextCodec::codecForName(fileNameCodecName);
+ p->fileNameCodec=QTextCodec::codecForName(fileNameCodecName);
+}
+
+void QuaZip::setOsCode(uint osCode)
+{
+ p->osCode = osCode;
+}
+
+uint QuaZip::getOsCode() const
+{
+ return p->osCode;
}
QTextCodec *QuaZip::getFileNameCodec()const
@@ -747,7 +785,7 @@ QList<QuaZipFileInfo64> QuaZip::getFileInfoList64() const
Qt::CaseSensitivity QuaZip::convertCaseSensitivity(QuaZip::CaseSensitivity cs)
{
if (cs == csDefault) {
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
return Qt::CaseInsensitive;
#else
return Qt::CaseSensitive;
@@ -767,6 +805,16 @@ void QuaZip::setDefaultFileNameCodec(const char *codecName)
setDefaultFileNameCodec(QTextCodec::codecForName(codecName));
}
+void QuaZip::setDefaultOsCode(uint osCode)
+{
+ QuaZipPrivate::defaultOsCode = osCode;
+}
+
+uint QuaZip::getDefaultOsCode()
+{
+ return QuaZipPrivate::defaultOsCode;
+}
+
void QuaZip::setZip64Enabled(bool zip64)
{
p->zip64 = zip64;
@@ -777,6 +825,16 @@ bool QuaZip::isZip64Enabled() const
return p->zip64;
}
+void QuaZip::setUtf8Enabled(bool utf8)
+{
+ p->utf8 = utf8;
+}
+
+bool QuaZip::isUtf8Enabled() const
+{
+ return p->utf8;
+}
+
bool QuaZip::isAutoClose() const
{
return p->autoClose;
diff --git a/rbutil/rbutilqt/quazip/quazip.h b/rbutil/rbutilqt/quazip/quazip.h
index ae2c8f494f..e57a64ae39 100644
--- a/rbutil/rbutilqt/quazip/quazip.h
+++ b/rbutil/rbutilqt/quazip/quazip.h
@@ -25,9 +25,9 @@ Original ZIP package is copyrighted by Gilles Vollant, see
quazip/(un)zip.h files for details, basically it's zlib license.
**/
-#include <QString>
-#include <QStringList>
-#include <QTextCodec>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QTextCodec>
#include "zip.h"
#include "unzip.h"
@@ -227,6 +227,14 @@ class QUAZIP_EXPORT QuaZip {
* Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));
**/
void setFileNameCodec(const char *fileNameCodecName);
+ /// Sets the OS code (highest 8 bits of the “version made by” field) for new files.
+ /** There is currently no way to specify this for each file individually,
+ except by calling this function before opening each file. If this function is not called,
+ then the default OS code will be used. The default code is set by calling
+ setDefaultOsCode(). The default value at the moment of QuaZip creation will be used. */
+ void setOsCode(uint osCode);
+ /// Returns the OS code for new files.
+ uint getOsCode() const;
/// Returns the codec used to encode/decode comments inside archive.
QTextCodec* getFileNameCodec() const;
/// Sets the codec used to encode/decode comments inside archive.
@@ -502,6 +510,28 @@ class QUAZIP_EXPORT QuaZip {
* \sa setZip64Enabled()
*/
bool isZip64Enabled() const;
+ /// Enables the use of UTF-8 encoding for file names and comments text.
+ /**
+ * @param utf8 If \c true, the UTF-8 mode is enabled, disabled otherwise.
+ *
+ * Once this is enabled, the names of all new files and comments text (until
+ * the mode is disabled again) will be encoded in UTF-8 encoding, and the
+ * version to extract will be set to 6.3 (63) in ZIP header. By default,
+ * the UTF-8 mode is off due to compatibility reasons.
+ *
+ * Note that when extracting ZIP archives, the UTF-8 mode is determined from
+ * ZIP file header, not from this flag.
+ *
+ * \sa isUtf8Enabled()
+ */
+ void setUtf8Enabled(bool utf8);
+ /// Returns whether the UTF-8 encoding mode is enabled.
+ /**
+ * @return \c true if and only if the UTF-8 mode is enabled.
+ *
+ * \sa setUtf8Enabled()
+ */
+ bool isUtf8Enabled() const;
/// Returns the auto-close flag.
/**
@sa setAutoClose()
@@ -563,9 +593,19 @@ class QUAZIP_EXPORT QuaZip {
/**
* @overload
* Equivalent to calling
- * setDefltFileNameCodec(QTextCodec::codecForName(codecName)).
+ * setDefaultFileNameCodec(QTextCodec::codecForName(codecName)).
*/
static void setDefaultFileNameCodec(const char *codecName);
+ /// Sets default OS code.
+ /**
+ * @sa setOsCode()
+ */
+ static void setDefaultOsCode(uint osCode);
+ /// Returns default OS code.
+ /**
+ * @sa getOsCode()
+ */
+ static uint getDefaultOsCode();
};
#endif
diff --git a/rbutil/rbutilqt/quazip/quazip.pri b/rbutil/rbutilqt/quazip/quazip.pri
index cae9d965c1..3a82bd0275 100644
--- a/rbutil/rbutilqt/quazip/quazip.pri
+++ b/rbutil/rbutilqt/quazip/quazip.pri
@@ -9,7 +9,7 @@ SOURCES += \
$$PWD/zip.c \
HEADERS += \
- $$PWD/crypt.h \
+ $$PWD/minizip_crypt.h \
$$PWD/ioapi.h \
$$PWD/quazipfile.h \
$$PWD/quazipfileinfo.h \
diff --git a/rbutil/rbutilqt/quazip/quazip_global.h b/rbutil/rbutilqt/quazip/quazip_global.h
index 7e3798afc1..de581bd7c4 100644
--- a/rbutil/rbutilqt/quazip/quazip_global.h
+++ b/rbutil/rbutilqt/quazip/quazip_global.h
@@ -48,12 +48,16 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#endif // QUAZIP_STATIC
#ifdef __GNUC__
-#define UNUSED __attribute__((__unused__))
+#define QUAZIP_UNUSED __attribute__((__unused__))
#else
-#define UNUSED
+#define QUAZIP_UNUSED
#endif
#define QUAZIP_EXTRA_NTFS_MAGIC 0x000Au
#define QUAZIP_EXTRA_NTFS_TIME_MAGIC 0x0001u
+#define QUAZIP_EXTRA_EXT_TIME_MAGIC 0x5455u
+#define QUAZIP_EXTRA_EXT_MOD_TIME_FLAG 1
+#define QUAZIP_EXTRA_EXT_AC_TIME_FLAG 2
+#define QUAZIP_EXTRA_EXT_CR_TIME_FLAG 4
#endif // QUAZIP_GLOBAL_H
diff --git a/rbutil/rbutilqt/quazip/quazipfile.cpp b/rbutil/rbutilqt/quazip/quazipfile.cpp
index 8d56417698..b984de7279 100644
--- a/rbutil/rbutilqt/quazip/quazipfile.cpp
+++ b/rbutil/rbutilqt/quazip/quazipfile.cpp
@@ -24,8 +24,12 @@ quazip/(un)zip.h files for details, basically it's zlib license.
#include "quazipfile.h"
+#include "quazipfileinfo.h"
+
using namespace std;
+#define QUAZIP_VERSION_MADE_BY 0x1Eu
+
/// The implementation class for QuaZip.
/**
\internal
@@ -37,6 +41,7 @@ technique known as the Pimpl (private implementation) idiom.
class QuaZipFilePrivate {
friend class QuaZipFile;
private:
+ Q_DISABLE_COPY(QuaZipFilePrivate)
/// The pointer to the associated QuaZipFile instance.
QuaZipFile *q;
/// The QuaZip object to work with.
@@ -76,27 +81,55 @@ class QuaZipFilePrivate {
void setZipError(int zipError) const;
/// The constructor for the corresponding QuaZipFile constructor.
inline QuaZipFilePrivate(QuaZipFile *q):
- q(q), zip(NULL), internal(true), zipError(UNZ_OK) {}
+ q(q),
+ zip(NULL),
+ caseSensitivity(QuaZip::csDefault),
+ raw(false),
+ writePos(0),
+ uncompressedSize(0),
+ crc(0),
+ internal(true),
+ zipError(UNZ_OK) {}
/// The constructor for the corresponding QuaZipFile constructor.
inline QuaZipFilePrivate(QuaZipFile *q, const QString &zipName):
- q(q), internal(true), zipError(UNZ_OK)
+ q(q),
+ caseSensitivity(QuaZip::csDefault),
+ raw(false),
+ writePos(0),
+ uncompressedSize(0),
+ crc(0),
+ internal(true),
+ zipError(UNZ_OK)
{
zip=new QuaZip(zipName);
}
/// The constructor for the corresponding QuaZipFile constructor.
inline QuaZipFilePrivate(QuaZipFile *q, const QString &zipName, const QString &fileName,
QuaZip::CaseSensitivity cs):
- q(q), internal(true), zipError(UNZ_OK)
+ q(q),
+ raw(false),
+ writePos(0),
+ uncompressedSize(0),
+ crc(0),
+ internal(true),
+ zipError(UNZ_OK)
{
zip=new QuaZip(zipName);
this->fileName=fileName;
- if (this->fileName.startsWith('/'))
+ if (this->fileName.startsWith(QLatin1String("/")))
this->fileName = this->fileName.mid(1);
this->caseSensitivity=cs;
}
/// The constructor for the QuaZipFile constructor accepting a file name.
inline QuaZipFilePrivate(QuaZipFile *q, QuaZip *zip):
- q(q), zip(zip), internal(false), zipError(UNZ_OK) {}
+ q(q),
+ zip(zip),
+ raw(false),
+ writePos(0),
+ uncompressedSize(0),
+ crc(0),
+ internal(false),
+ zipError(UNZ_OK) {}
/// The destructor.
inline ~QuaZipFilePrivate()
{
@@ -203,7 +236,7 @@ void QuaZipFile::setFileName(const QString& fileName, QuaZip::CaseSensitivity cs
return;
}
p->fileName=fileName;
- if (p->fileName.startsWith('/'))
+ if (p->fileName.startsWith(QLatin1String("/")))
p->fileName = p->fileName.mid(1);
p->caseSensitivity=cs;
}
@@ -310,14 +343,22 @@ bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
zipSetFlags(p->zip->getZipFile(), ZIP_WRITE_DATA_DESCRIPTOR);
else
zipClearFlags(p->zip->getZipFile(), ZIP_WRITE_DATA_DESCRIPTOR);
- p->setZipError(zipOpenNewFileInZip3_64(p->zip->getZipFile(),
- p->zip->getFileNameCodec()->fromUnicode(info.name).constData(), &info_z,
+ p->setZipError(zipOpenNewFileInZip4_64(p->zip->getZipFile(),
+ p->zip->isUtf8Enabled()
+ ? info.name.toUtf8().constData()
+ : p->zip->getFileNameCodec()->fromUnicode(info.name).constData(),
+ &info_z,
info.extraLocal.constData(), info.extraLocal.length(),
info.extraGlobal.constData(), info.extraGlobal.length(),
- p->zip->getCommentCodec()->fromUnicode(info.comment).constData(),
+ p->zip->isUtf8Enabled()
+ ? info.comment.toUtf8().constData()
+ : p->zip->getCommentCodec()->fromUnicode(info.comment).constData(),
method, level, (int)raw,
windowBits, memLevel, strategy,
- password, (uLong)crc, p->zip->isZip64Enabled()));
+ password, (uLong)crc,
+ (p->zip->getOsCode() << 8) | QUAZIP_VERSION_MADE_BY,
+ 0,
+ p->zip->isZip64Enabled()));
if(p->zipError==UNZ_OK) {
p->writePos=0;
setOpenMode(mode);
@@ -353,7 +394,7 @@ qint64 QuaZipFile::pos()const
// QIODevice::pos() is broken for sequential devices,
// but thankfully bytesAvailable() returns the number of
// bytes buffered, so we know how far ahead we are.
- return unztell(p->zip->getUnzFile()) - QIODevice::bytesAvailable();
+ return unztell64(p->zip->getUnzFile()) - QIODevice::bytesAvailable();
else
return p->writePos;
}
@@ -500,3 +541,30 @@ qint64 QuaZipFile::bytesAvailable() const
{
return size() - pos();
}
+
+QByteArray QuaZipFile::getLocalExtraField()
+{
+ int size = unzGetLocalExtrafield(p->zip->getUnzFile(), NULL, 0);
+ QByteArray extra(size, '\0');
+ int err = unzGetLocalExtrafield(p->zip->getUnzFile(), extra.data(), static_cast<uint>(extra.size()));
+ if (err < 0) {
+ p->setZipError(err);
+ return QByteArray();
+ }
+ return extra;
+}
+
+QDateTime QuaZipFile::getExtModTime()
+{
+ return QuaZipFileInfo64::getExtTime(getLocalExtraField(), QUAZIP_EXTRA_EXT_MOD_TIME_FLAG);
+}
+
+QDateTime QuaZipFile::getExtAcTime()
+{
+ return QuaZipFileInfo64::getExtTime(getLocalExtraField(), QUAZIP_EXTRA_EXT_AC_TIME_FLAG);
+}
+
+QDateTime QuaZipFile::getExtCrTime()
+{
+ return QuaZipFileInfo64::getExtTime(getLocalExtraField(), QUAZIP_EXTRA_EXT_CR_TIME_FLAG);
+}
diff --git a/rbutil/rbutilqt/quazip/quazipfile.h b/rbutil/rbutilqt/quazip/quazipfile.h
index e27b7a4a6c..0fd6829f36 100644
--- a/rbutil/rbutilqt/quazip/quazipfile.h
+++ b/rbutil/rbutilqt/quazip/quazipfile.h
@@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant, see
quazip/(un)zip.h files for details, basically it's zlib license.
**/
-#include <QIODevice>
+#include <QtCore/QIODevice>
#include "quazip_global.h"
#include "quazip.h"
@@ -451,6 +451,58 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
int getZipError() const;
/// Returns the number of bytes available for reading.
virtual qint64 bytesAvailable() const;
+ /// Returns the local extra field
+ /**
+ There are two (optional) local extra fields associated with a file.
+ One is located in the central header and is available along
+ with the rest of the file information in @ref QuaZipFileInfo64::extra.
+ Another is located before the file itself,
+ and is returned by this function. The file must be open first.
+
+ @return the local extra field, or an empty array if there is none
+ (or file is not open)
+ */
+ QByteArray getLocalExtraField();
+ /// Returns the extended modification timestamp
+ /**
+ * The getExt*Time() functions only work if there is an extended timestamp
+ * extra field (ID 0x5455) present. Otherwise, they all return invalid null
+ * timestamps.
+ *
+ * Modification time, but not other times, can also be accessed through
+ * @ref QuaZipFileInfo64 without the need to open the file first.
+ *
+ * @sa dateTime
+ * @sa QuaZipFileInfo64::getExtModTime()
+ * @sa getExtAcTime()
+ * @sa getExtCrTime()
+ * @return The extended modification time, UTC
+ */
+ QDateTime getExtModTime();
+ /// Returns the extended access timestamp
+ /**
+ * The getExt*Time() functions only work if there is an extended timestamp
+ * extra field (ID 0x5455) present. Otherwise, they all return invalid null
+ * timestamps.
+ * @sa dateTime
+ * @sa QuaZipFileInfo64::getExtModTime()
+ * @sa getExtModTime()
+ * @sa getExtCrTime()
+ * @return The extended access time, UTC
+ */
+ QDateTime getExtAcTime();
+ /// Returns the extended creation timestamp
+ /**
+ * The getExt*Time() functions only work if there is an extended timestamp
+ * extra field (ID 0x5455) present. Otherwise, they all return invalid null
+ * timestamps.
+ * @sa dateTime
+ * @sa QuaZipFileInfo64::getExtModTime()
+ * @sa getExtModTime()
+ * @sa getExtAcTime()
+ * @return The extended creation time, UTC
+ */
+ QDateTime getExtCrTime();
};
#endif
diff --git a/rbutil/rbutilqt/quazip/quazipfileinfo.cpp b/rbutil/rbutilqt/quazip/quazipfileinfo.cpp
index 1961f116b3..d5798ea771 100644
--- a/rbutil/rbutilqt/quazip/quazipfileinfo.cpp
+++ b/rbutil/rbutilqt/quazip/quazipfileinfo.cpp
@@ -24,6 +24,8 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "quazipfileinfo.h"
+#include <QtCore/QDataStream>
+
static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr) {
quint32 uPerm = (externalAttr & 0xFFFF0000u) >> 16;
QFile::Permissions perm = QFile::Permissions();
@@ -93,69 +95,30 @@ static QDateTime getNTFSTime(const QByteArray &extra, int position,
int *fineTicks)
{
QDateTime dateTime;
- for (int i = 0; i <= extra.size() - 4; ) {
- unsigned type = static_cast<unsigned>(static_cast<unsigned char>(
- extra.at(i)))
- | (static_cast<unsigned>(static_cast<unsigned char>(
- extra.at(i + 1))) << 8);
- i += 2;
- unsigned length = static_cast<unsigned>(static_cast<unsigned char>(
- extra.at(i)))
- | (static_cast<unsigned>(static_cast<unsigned char>(
- extra.at(i + 1))) << 8);
- i += 2;
- if (type == QUAZIP_EXTRA_NTFS_MAGIC && length >= 32) {
- i += 4; // reserved
- while (i <= extra.size() - 4) {
- unsigned tag = static_cast<unsigned>(
- static_cast<unsigned char>(extra.at(i)))
- | (static_cast<unsigned>(
- static_cast<unsigned char>(extra.at(i + 1)))
- << 8);
- i += 2;
- int tagsize = static_cast<unsigned>(
- static_cast<unsigned char>(extra.at(i)))
- | (static_cast<unsigned>(
- static_cast<unsigned char>(extra.at(i + 1)))
- << 8);
- i += 2;
- if (tag == QUAZIP_EXTRA_NTFS_TIME_MAGIC
- && tagsize >= position + 8) {
- i += position;
- quint64 mtime = static_cast<quint64>(
- static_cast<unsigned char>(extra.at(i)))
- | (static_cast<quint64>(static_cast<unsigned char>(
- extra.at(i + 1))) << 8)
- | (static_cast<quint64>(static_cast<unsigned char>(
- extra.at(i + 2))) << 16)
- | (static_cast<quint64>(static_cast<unsigned char>(
- extra.at(i + 3))) << 24)
- | (static_cast<quint64>(static_cast<unsigned char>(
- extra.at(i + 4))) << 32)
- | (static_cast<quint64>(static_cast<unsigned char>(
- extra.at(i + 5))) << 40)
- | (static_cast<quint64>(static_cast<unsigned char>(
- extra.at(i + 6))) << 48)
- | (static_cast<quint64>(static_cast<unsigned char>(
- extra.at(i + 7))) << 56);
- // the NTFS time is measured from 1601 for whatever reason
- QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
- dateTime = base.addMSecs(mtime / 10000);
- if (fineTicks != NULL) {
- *fineTicks = static_cast<int>(mtime % 10000);
- }
- i += tagsize - position;
- } else {
- i += tagsize;
- }
-
- }
- } else {
- i += length;
- }
- }
- if (fineTicks != NULL && dateTime.isNull()) {
- *fineTicks = 0;
+ QuaExtraFieldHash extraHash = QuaZipFileInfo64::parseExtraField(extra);
+ QList<QByteArray> ntfsExtraFields = extraHash[QUAZIP_EXTRA_NTFS_MAGIC];
+ if (ntfsExtraFields.isEmpty())
+ return dateTime;
+ QByteArray ntfsExtraField = ntfsExtraFields.at(0);
+ if (ntfsExtraField.length() <= 4)
+ return dateTime;
+ QByteArray ntfsAttributes = ntfsExtraField.mid(4);
+ QuaExtraFieldHash ntfsHash = QuaZipFileInfo64::parseExtraField(ntfsAttributes);
+ QList<QByteArray> ntfsTimeAttributes = ntfsHash[QUAZIP_EXTRA_NTFS_TIME_MAGIC];
+ if (ntfsTimeAttributes.isEmpty())
+ return dateTime;
+ QByteArray ntfsTimes = ntfsTimeAttributes.at(0);
+ if (ntfsTimes.size() < 24)
+ return dateTime;
+ QDataStream timeReader(ntfsTimes);
+ timeReader.setByteOrder(QDataStream::LittleEndian);
+ timeReader.device()->seek(position);
+ quint64 time;
+ timeReader >> time;
+ QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
+ dateTime = base.addMSecs(time / 10000);
+ if (fineTicks != NULL) {
+ *fineTicks = static_cast<int>(time % 10000);
}
return dateTime;
}
@@ -174,3 +137,60 @@ QDateTime QuaZipFileInfo64::getNTFScTime(int *fineTicks) const
{
return getNTFSTime(extra, 16, fineTicks);
}
+
+QDateTime QuaZipFileInfo64::getExtTime(const QByteArray &extra, int flag)
+{
+ QDateTime dateTime;
+ QuaExtraFieldHash extraHash = QuaZipFileInfo64::parseExtraField(extra);
+ QList<QByteArray> extTimeFields = extraHash[QUAZIP_EXTRA_EXT_TIME_MAGIC];
+ if (extTimeFields.isEmpty())
+ return dateTime;
+ QByteArray extTimeField = extTimeFields.at(0);
+ if (extTimeField.length() < 1)
+ return dateTime;
+ QDataStream input(extTimeField);
+ input.setByteOrder(QDataStream::LittleEndian);
+ quint8 flags;
+ input >> flags;
+ int flagsRemaining = flags;
+ while (!input.atEnd()) {
+ int nextFlag = flagsRemaining & -flagsRemaining;
+ flagsRemaining &= flagsRemaining - 1;
+ qint32 time;
+ input >> time;
+ if (nextFlag == flag) {
+ QDateTime base(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC);
+ dateTime = base.addSecs(time);
+ return dateTime;
+ }
+ }
+ return dateTime;
+}
+
+QDateTime QuaZipFileInfo64::getExtModTime() const
+{
+ return getExtTime(extra, 1);
+}
+
+QuaExtraFieldHash QuaZipFileInfo64::parseExtraField(const QByteArray &extraField)
+{
+ QDataStream input(extraField);
+ input.setByteOrder(QDataStream::LittleEndian);
+ QHash<quint16, QList<QByteArray> > result;
+ while (!input.atEnd()) {
+ quint16 id, size;
+ input >> id;
+ if (input.status() == QDataStream::ReadPastEnd)
+ return result;
+ input >> size;
+ if (input.status() == QDataStream::ReadPastEnd)
+ return result;
+ QByteArray data;
+ data.resize(size);
+ int read = input.readRawData(data.data(), data.size());
+ if (read < data.size())
+ return result;
+ result[id] << data;
+ }
+ return result;
+}
diff --git a/rbutil/rbutilqt/quazip/quazipfileinfo.h b/rbutil/rbutilqt/quazip/quazipfileinfo.h
index 4e142a4eb5..43665b4ac2 100644
--- a/rbutil/rbutilqt/quazip/quazipfileinfo.h
+++ b/rbutil/rbutilqt/quazip/quazipfileinfo.h
@@ -25,12 +25,16 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/
-#include <QByteArray>
-#include <QDateTime>
-#include <QFile>
+#include <QtCore/QByteArray>
+#include <QtCore/QDateTime>
+#include <QtCore/QFile>
+#include <QtCore/QHash>
#include "quazip_global.h"
+/// The typedef to store extra field parse results
+typedef QHash<quint16, QList<QByteArray> > QuaExtraFieldHash;
+
/// Information about a file inside archive.
/**
* \deprecated Use QuaZipFileInfo64 instead. Not only it supports large files,
@@ -171,8 +175,52 @@ struct QUAZIP_EXPORT QuaZipFileInfo64 {
* @return The NTFS creation time, UTC
*/
QDateTime getNTFScTime(int *fineTicks = NULL) const;
+ /// Returns the extended modification timestamp
+ /**
+ * The getExt*Time() functions only work if there is an extended timestamp
+ * extra field (ID 0x5455) present. Otherwise, they all return invalid null
+ * timestamps.
+ *
+ * QuaZipFileInfo64 only contains the modification time because it's extracted
+ * from @ref extra, which contains the global extra field, and access and
+ * creation time are in the local header which can be accessed through
+ * @ref QuaZipFile.
+ *
+ * @sa dateTime
+ * @sa QuaZipFile::getExtModTime()
+ * @sa QuaZipFile::getExtAcTime()
+ * @sa QuaZipFile::getExtCrTime()
+ * @return The extended modification time, UTC
+ */
+ QDateTime getExtModTime() const;
/// Checks whether the file is encrypted.
bool isEncrypted() const {return (flags & 1) != 0;}
+ /// Parses extra field
+ /**
+ * The returned hash table contains a list of data blocks for every header ID
+ * in the provided extra field. The number of data blocks in a hash table value
+ * equals to the number of occurrences of the appropriate header id. In most cases,
+ * a block with a specific header ID only occurs once, and therefore the returned
+ * hash table will contain a list consisting of a single element for that header ID.
+ *
+ * @param extraField extra field to parse
+ * @return header id to list of data block hash
+ */
+ static QuaExtraFieldHash parseExtraField(const QByteArray &extraField);
+ /// Extracts extended time from the extra field
+ /**
+ * Utility function used by various getExt*Time() functions, but can be used directly
+ * if the extra field is obtained elsewhere (from a third party library, for example).
+ *
+ * @param extra the extra field for a file
+ * @param flag 1 - modification time, 2 - access time, 4 - creation time
+ * @return the extracted time or null QDateTime if not present
+ * @sa getExtModTime()
+ * @sa QuaZipFile::getExtModTime()
+ * @sa QuaZipFile::getExtAcTime()
+ * @sa QuaZipFile::getExtCrTime()
+ */
+ static QDateTime getExtTime(const QByteArray &extra, int flag);
};
#endif
diff --git a/rbutil/rbutilqt/quazip/quazipnewinfo.cpp b/rbutil/rbutilqt/quazip/quazipnewinfo.cpp
index 02e01da9c5..98630e086a 100644
--- a/rbutil/rbutilqt/quazip/quazipnewinfo.cpp
+++ b/rbutil/rbutilqt/quazip/quazipnewinfo.cpp
@@ -22,16 +22,25 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/
-#include <QFileInfo>
+#include <QtCore/QFileInfo>
#include "quazipnewinfo.h"
#include <string.h>
static void QuaZipNewInfo_setPermissions(QuaZipNewInfo *info,
- QFile::Permissions perm, bool isDir)
+ QFile::Permissions perm, bool isDir, bool isSymLink = false)
{
quint32 uPerm = isDir ? 0040000 : 0100000;
+
+ if ( isSymLink ) {
+#ifdef Q_OS_WIN
+ uPerm = 0200000;
+#else
+ uPerm = 0120000;
+#endif
+ }
+
if ((perm & QFile::ReadOwner) != 0)
uPerm |= 0400;
if ((perm & QFile::WriteOwner) != 0)
@@ -91,7 +100,7 @@ QuaZipNewInfo::QuaZipNewInfo(const QString& name, const QString& file):
dateTime = QDateTime::currentDateTime();
} else {
dateTime = lm;
- QuaZipNewInfo_setPermissions(this, info.permissions(), info.isDir());
+ QuaZipNewInfo_setPermissions(this, info.permissions(), info.isDir(), info.isSymLink());
}
}
@@ -107,12 +116,12 @@ void QuaZipNewInfo::setFilePermissions(const QString &file)
{
QFileInfo info = QFileInfo(file);
QFile::Permissions perm = info.permissions();
- QuaZipNewInfo_setPermissions(this, perm, info.isDir());
+ QuaZipNewInfo_setPermissions(this, perm, info.isDir(), info.isSymLink());
}
void QuaZipNewInfo::setPermissions(QFile::Permissions permissions)
{
- QuaZipNewInfo_setPermissions(this, permissions, name.endsWith('/'));
+ QuaZipNewInfo_setPermissions(this, permissions, name.endsWith(QLatin1String("/")));
}
void QuaZipNewInfo::setFileNTFSTimes(const QString &fileName)
@@ -125,7 +134,11 @@ void QuaZipNewInfo::setFileNTFSTimes(const QString &fileName)
}
setFileNTFSmTime(fi.lastModified());
setFileNTFSaTime(fi.lastRead());
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
+ setFileNTFScTime(fi.birthTime());
+#else
setFileNTFScTime(fi.created());
+#endif
}
static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position,
diff --git a/rbutil/rbutilqt/quazip/quazipnewinfo.h b/rbutil/rbutilqt/quazip/quazipnewinfo.h
index bfd498682f..43a1e6fd08 100644
--- a/rbutil/rbutilqt/quazip/quazipnewinfo.h
+++ b/rbutil/rbutilqt/quazip/quazipnewinfo.h
@@ -25,9 +25,9 @@ Original ZIP package is copyrighted by Gilles Vollant, see
quazip/(un)zip.h files for details, basically it's zlib license.
**/
-#include <QDateTime>
-#include <QFile>
-#include <QString>
+#include <QtCore/QDateTime>
+#include <QtCore/QFile>
+#include <QtCore/QString>
#include "quazip_global.h"
@@ -70,7 +70,7 @@ struct QUAZIP_EXPORT QuaZipNewInfo {
*/
quint32 externalAttr;
/// File comment.
- /** Will be encoded using QuaZip::getCommentCodec().
+ /** Will be encoded in UTF-8 encoding.
**/
QString comment;
/// File local extra field.
@@ -148,8 +148,9 @@ struct QUAZIP_EXPORT QuaZipNewInfo {
/**
* If the file doesn't exist, a warning is printed to the stderr and nothing
* is done. Otherwise, all three times, as reported by
- * QFileInfo::lastModified(), QFileInfo::lastRead() and QFileInfo::created(),
- * are written to the NTFS extra field record.
+ * QFileInfo::lastModified(), QFileInfo::lastRead() and
+ * QFileInfo::birthTime() (>=Qt5.10) or QFileInfo::created(), are written to
+ * the NTFS extra field record.
*
* The NTFS record is written to
* both the local and the global extra fields, updating the existing record
diff --git a/rbutil/rbutilqt/quazip/unzip.c b/rbutil/rbutilqt/quazip/unzip.c
index bca03f8323..6aaeba6930 100644
--- a/rbutil/rbutilqt/quazip/unzip.c
+++ b/rbutil/rbutilqt/quazip/unzip.c
@@ -15,6 +15,8 @@
For more info read MiniZip_info.txt
+ Modifications for static code analysis report
+ Copyright (C) 2016 Intel Deutschland GmbH
------------------------------------------------------------------------------------
Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
@@ -28,7 +30,7 @@
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
- crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
+ crypt.c (full version) by Info-ZIP. Last revised: [see minizip_crypt.h]
The encryption/decryption parts of this source code (as opposed to the
non-echoing password parts) were originally written in Europe. The
@@ -71,7 +73,7 @@
#include <stdlib.h>
#include <string.h>
-#include "zlib.h"
+#include <zlib.h>
#if (ZLIB_VERNUM < 0x1270)
typedef uLongf z_crc_t;
#endif
@@ -197,7 +199,7 @@ typedef struct
#ifndef NOUNCRYPT
-#include "crypt.h"
+#include "minizip_crypt.h"
#endif
/* ===========================================================================
@@ -856,6 +858,17 @@ extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info
pglobal_info32->size_comment = s->gi.size_comment;
return UNZ_OK;
}
+
+extern int ZEXPORT unzGetFileFlags (unzFile file, unsigned* pflags)
+{
+ unz64_s* s;
+ if (file==NULL)
+ return UNZ_PARAMERROR;
+ s=(unz64_s*)file;
+ *pflags = s->flags;
+ return UNZ_OK;
+}
+
/*
Translate date/time from Dos format to tm_unz (readable more easilty)
*/
@@ -1198,6 +1211,8 @@ extern int ZEXPORT unzGoToFirstFile (unzFile file)
&s->cur_file_info_internal,
NULL,0,NULL,0,NULL,0);
s->current_file_ok = (err == UNZ_OK);
+ if (s->cur_file_info.flag & UNZ_ENCODING_UTF8)
+ unzSetFlags(file, UNZ_ENCODING_UTF8);
return err;
}
@@ -1594,6 +1609,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
else
{
+ TRYFREE(pfile_in_zip_read_info->read_buffer);
TRYFREE(pfile_in_zip_read_info);
return err;
}
@@ -1845,38 +1861,30 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
} /* end Z_BZIP2ED */
else
{
- ZPOS64_T uTotalOutBefore,uTotalOutAfter;
+ uInt uAvailOutBefore,uAvailOutAfter;
const Bytef *bufBefore;
- ZPOS64_T uOutThis;
+ uInt uOutThis;
int flush=Z_SYNC_FLUSH;
- uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
+ uAvailOutBefore = pfile_in_zip_read_info->stream.avail_out;
bufBefore = pfile_in_zip_read_info->stream.next_out;
- /*
- if ((pfile_in_zip_read_info->rest_read_uncompressed ==
- pfile_in_zip_read_info->stream.avail_out) &&
- (pfile_in_zip_read_info->rest_read_compressed == 0))
- flush = Z_FINISH;
- */
err=inflate(&pfile_in_zip_read_info->stream,flush);
if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
err = Z_DATA_ERROR;
- uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
- uOutThis = uTotalOutAfter-uTotalOutBefore;
+ uAvailOutAfter = pfile_in_zip_read_info->stream.avail_out;
+ uOutThis = uAvailOutBefore - uAvailOutAfter;
pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
- pfile_in_zip_read_info->crc32 =
- crc32(pfile_in_zip_read_info->crc32,bufBefore,
- (uInt)(uOutThis));
+ pfile_in_zip_read_info->crc32
+ = crc32(pfile_in_zip_read_info->crc32,bufBefore, uOutThis);
- pfile_in_zip_read_info->rest_read_uncompressed -=
- uOutThis;
+ pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
- iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
+ iRead += uAvailOutBefore - uAvailOutAfter;
if (err==Z_STREAM_END)
return (iRead==0) ? UNZ_EOF : iRead;
diff --git a/rbutil/rbutilqt/quazip/unzip.h b/rbutil/rbutilqt/quazip/unzip.h
index da7b062845..fdefa2217a 100644
--- a/rbutil/rbutilqt/quazip/unzip.h
+++ b/rbutil/rbutilqt/quazip/unzip.h
@@ -53,7 +53,7 @@ extern "C" {
#endif
#ifndef _ZLIB_H
-#include "zlib.h"
+#include <zlib.h>
#endif
#ifndef _ZLIBIOAPI_H
@@ -87,6 +87,7 @@ typedef voidp unzFile;
#define UNZ_AUTO_CLOSE 0x01u
#define UNZ_DEFAULT_FLAGS UNZ_AUTO_CLOSE
+#define UNZ_ENCODING_UTF8 0x0800u
/* tm_unz contain date/time info */
typedef struct tm_unz_s
@@ -227,6 +228,8 @@ extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
unz_global_info64 *pglobal_info));
+
+extern int ZEXPORT unzGetFileFlags OF((unzFile file, unsigned* pflags));
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
diff --git a/rbutil/rbutilqt/quazip/zip.c b/rbutil/rbutilqt/quazip/zip.c
index 96496539f4..0f3deb04c1 100644
--- a/rbutil/rbutilqt/quazip/zip.c
+++ b/rbutil/rbutilqt/quazip/zip.c
@@ -12,6 +12,9 @@
Modifications for QIODevice support and other QuaZIP fixes
Copyright (C) 2005-2014 Sergey A. Tachenov
+ Fixing static code analysis issues
+ Copyright (C) 2016 Intel Deutschland GmbH
+
Changes
Oct-2009 - Mathias Svensson - Remove old C style function prototypes
Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
@@ -29,7 +32,8 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include "zlib.h"
+
+#include <zlib.h>
#if (ZLIB_VERNUM < 0x1270)
typedef uLongf z_crc_t;
#endif
@@ -192,7 +196,7 @@ typedef struct
#ifndef NOCRYPT
#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
-#include "crypt.h"
+#include "minizip_crypt.h"
#endif
local linkedlist_datablock_internal* allocate_new_datablock()
@@ -527,13 +531,14 @@ local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f
if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
break;
- for (i=(int)uReadSize-3; (i--)>0;)
+ for (i=(int)uReadSize-3; (i--)>0;){
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
{
uPosFound = uReadPos+i;
break;
}
+ }
if (uPosFound!=0)
break;
@@ -988,7 +993,9 @@ int Write_LocalFileHeader(zip64_internal* zi, const char* filename,
if (err==ZIP_OK)
{
- if(zi->ci.zip64)
+ if(zi->ci.flag & ZIP_ENCODING_UTF8)
+ err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)63,2);/* Version 6.3 is required for Unicode support */
+ else if(zi->ci.zip64)
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
else
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)version_to_extract,2);
@@ -1146,6 +1153,8 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
}
zi->ci.flag = flagBase;
+ if (zi->flags & ZIP_ENCODING_UTF8)
+ zi->ci.flag |= ZIP_ENCODING_UTF8;
if ((level==8) || (level==9))
zi->ci.flag |= 2;
if (level==2)
@@ -1171,6 +1180,9 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
zi->ci.size_centralExtraFree = 32; /* Extra space we have reserved in case we need to add ZIP64 extra info data */
zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
+ if(!zi->ci.central_header) {
+ return (Z_MEM_ERROR);
+ }
zi->ci.size_centralExtra = size_extrafield_global;
zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
@@ -1509,15 +1521,9 @@ extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned in
if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
{
- uLong uTotalOutBefore = zi->ci.stream.total_out;
+ uInt uAvailOutBefore = zi->ci.stream.avail_out;
err=deflate(&zi->ci.stream, Z_NO_FLUSH);
- if(uTotalOutBefore > zi->ci.stream.total_out)
- {
- int bBreak = 0;
- bBreak++;
- }
-
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
+ zi->ci.pos_in_buffered_data += uAvailOutBefore - zi->ci.stream.avail_out;
}
else
{
@@ -1571,7 +1577,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
{
while (err==ZIP_OK)
{
- uLong uTotalOutBefore;
+ uLong uAvailOutBefore;
if (zi->ci.stream.avail_out == 0)
{
if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
@@ -1579,9 +1585,9 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
zi->ci.stream.next_out = zi->ci.buffered_data;
}
- uTotalOutBefore = zi->ci.stream.total_out;
+ uAvailOutBefore = zi->ci.stream.avail_out;
err=deflate(&zi->ci.stream, Z_FINISH);
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
+ zi->ci.pos_in_buffered_data += uAvailOutBefore - zi->ci.stream.avail_out;
}
}
else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
@@ -1654,8 +1660,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
/*version Made by*/
zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
/*version needed*/
- zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
-
+ zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)((zi->ci.flag & ZIP_ENCODING_UTF8) ? 63 : 45),2);
}
zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
@@ -1737,7 +1742,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
if (err==ZIP_OK)
err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
- free(zi->ci.central_header);
+ TRYFREE(zi->ci.central_header);
if (err==ZIP_OK)
{
@@ -1849,7 +1854,7 @@ int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centra
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
if (err==ZIP_OK) /* version needed */
- err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
+ err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)((zi->ci.flag & ZIP_ENCODING_UTF8) ? 63 : 45),2);
if (err==ZIP_OK) /* number of this disk */
err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
@@ -2031,6 +2036,9 @@ extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHe
return ZIP_PARAMERROR;
pNewHeader = (char*)ALLOC(*dataLen);
+ if(!pNewHeader) {
+ return Z_MEM_ERROR;
+ }
pTmp = pNewHeader;
while(p < (pData + *dataLen))
diff --git a/rbutil/rbutilqt/quazip/zip.h b/rbutil/rbutilqt/quazip/zip.h
index a6617add0f..114a1bf6e7 100644
--- a/rbutil/rbutilqt/quazip/zip.h
+++ b/rbutil/rbutilqt/quazip/zip.h
@@ -53,7 +53,7 @@ extern "C" {
//#define HAVE_BZIP2
#ifndef _ZLIB_H
-#include "zlib.h"
+#include <zlib.h>
#endif
#ifndef _ZLIBIOAPI_H
@@ -85,6 +85,7 @@ typedef voidp zipFile;
#define ZIP_WRITE_DATA_DESCRIPTOR 0x8u
#define ZIP_AUTO_CLOSE 0x1u
#define ZIP_SEQUENTIAL 0x2u
+#define ZIP_ENCODING_UTF8 0x0800u
#define ZIP_DEFAULT_FLAGS (ZIP_AUTO_CLOSE | ZIP_WRITE_DATA_DESCRIPTOR)
#ifndef DEF_MEM_LEVEL