bool ok = false;
QFile file(realname);
- if (!file.open(QIODevice::ReadOnly))
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Unbuffered))
return false;
qint64 fileSize = file.size();
- if (!fileSize || quint32(-1) <= fileSize)
+ if (fileSize <= MagicLength || quint32(-1) <= fileSize)
return false;
+
+ {
+ char magicBuffer[MagicLength];
+ if (MagicLength != file.read(magicBuffer, MagicLength)
+ || memcmp(magicBuffer, magic, MagicLength))
+ return false;
+ }
+
d->unmapLength = quint32(fileSize);
#ifdef QT_USE_MMAP
if (!ok) {
d->unmapPointer = new char[d->unmapLength];
if (d->unmapPointer) {
+ file.seek(0);
qint64 readResult = file.read(d->unmapPointer, d->unmapLength);
if (readResult == qint64(unmapLength))
ok = true;
{
Q_D(QTranslator);
d->clear();
+
+ if (!data || len < MagicLength || memcmp(data, magic, MagicLength))
+ return false;
+
return d->do_load(data, len);
}
bool QTranslatorPrivate::do_load(const uchar *data, int len)
{
- if (!data || len < MagicLength || memcmp(data, magic, MagicLength))
- return false;
-
bool ok = true;
const uchar *end = data + len;