diff options
author | David Faure <david.faure@kdab.com> | 2016-12-26 13:38:21 +0100 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2016-12-27 08:44:32 +0000 |
commit | 7322c65ba70bc93d034dc570dd314dc9d738f0fa (patch) | |
tree | bb918401d07199ae8d69bb2e56b2f4d16cd22abc /src/corelib/mimetypes/qmimemagicrule.cpp | |
parent | 9efd29d1e27702fadcdfa207c9605fcb5b6b8dba (diff) |
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>
Diffstat (limited to 'src/corelib/mimetypes/qmimemagicrule.cpp')
-rw-r--r-- | src/corelib/mimetypes/qmimemagicrule.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/mimetypes/qmimemagicrule.cpp b/src/corelib/mimetypes/qmimemagicrule.cpp index 7e07f8acb9..7a807dccdb 100644 --- a/src/corelib/mimetypes/qmimemagicrule.cpp +++ b/src/corelib/mimetypes/qmimemagicrule.cpp @@ -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; |