diff options
-rw-r--r-- | src/corelib/io/qresource.cpp | 17 | ||||
-rw-r--r-- | tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp | 6 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index b85bca8590..8c1bfc8c48 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -1503,14 +1503,25 @@ uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::Memory { Q_Q(QResourceFileEngine); Q_UNUSED(flags); + + qint64 max = resource.size(); + if (resource.isCompressed()) { + uncompress(); + max = uncompressed.size(); + } + qint64 end; if (offset < 0 || size <= 0 || !resource.isValid() || - add_overflow(offset, size, &end) || end > resource.size()) { + add_overflow(offset, size, &end) || end > max) { q->setError(QFile::UnspecifiedError, QString()); return 0; } - uchar *address = const_cast<uchar *>(resource.data()); - return (address + offset); + + const uchar *address = resource.data(); + if (resource.isCompressed()) + address = reinterpret_cast<const uchar *>(uncompressed.constData()); + + return const_cast<uchar *>(address) + offset; } bool QResourceFileEnginePrivate::unmap(uchar *ptr) diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index cf1d249f54..6461e6274f 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -404,6 +404,12 @@ void tst_QResourceEngine::checkStructure() // check contents QCOMPARE(file.readAll(), contents); + + // check memory map too + uchar *ptr = file.map(0, file.size(), QFile::MapPrivateOption); + QVERIFY2(ptr, qPrintable(file.errorString())); + QByteArray ba = QByteArray::fromRawData(reinterpret_cast<const char *>(ptr), file.size()); + QCOMPARE(ba, contents); } QLocale::setDefault(QLocale::system()); } |