QResourceFileEngine: fix map() for compressed files
We were returning a pointer to the compressed data and comparing to the compressed data size. Change-Id: I343f2beed55440a7ac0bfffd1563232d557c9427 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
parent
460866ee47
commit
6a792d6f0b
@ -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)
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user