QMimeMagicRule: fix off by one in the number of bytes checked

Since the loop says p <= e, no +1 should be added to e.

Testcase:

The magic for application/x-gameboy-rom says
<match type="byte" value="0x0" mask="0x80" offset="323"/>
and this code was checking both byte 323 and byte 324, finding a match
at pos 324, returning application/x-gameboy-rom erroneously.

Given the magic for application/x-gameboy-color-rom:
<match type="byte" value="0x80" mask="0x80" offset="323"/>
the expected result for game-boy-color-test.gbc is application/x-gameboy-color-rom

Not yet detected by tst_qmimedatabase which is based on shared-mime-info 1.0,
will be covered by the upgrade to 1.8.

Change-Id: I2396cb1ccfb26db5a24d5551fef493cc0b98a247
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
David Faure 2016-12-26 13:38:21 +01:00
parent 9efd29d1e2
commit 7322c65ba7

View File

@ -161,7 +161,7 @@ bool QMimeMagicRule::matchNumber(const QByteArray &data) const
//qDebug() << "mask" << QString::number(m_numberMask, 16);
const char *p = data.constData() + m_startPos;
const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), m_endPos + 1);
const char *e = data.constData() + qMin(data.size() - int(sizeof(T)), m_endPos);
for ( ; p <= e; ++p) {
if ((qFromUnaligned<T>(p) & mask) == (value & mask))
return true;