--- src/gui/text/qfontengine.cpp.orig
+++ src/gui/text/qfontengine.cpp
+static inline bool qSafeFromBigEndian(const uchar *source, const uchar *end, T *output)
+ if (source + sizeof(T) > end)
+ *output = qFromBigEndian<T>(source);
// Harfbuzz helper functions
static HB_Bool hb_stringToGlyphs(HB_Font font, const HB_UChar16 *string, hb_uint32 length, HB_Glyph *glyphs, hb_uint32 *numGlyphs, HB_Bool rightToLeft)
const uchar *table = reinterpret_cast<const uchar *>(tab.constData());
+ const uchar *end = table + tab.size();
+ if (!qSafeFromBigEndian(table, end, &version))
- unsigned short version = qFromBigEndian<quint16>(table);
// qDebug("wrong version");
- unsigned short numTables = qFromBigEndian<quint16>(table + 2);
+ if (!qSafeFromBigEndian(table + 2, end, &numTables))
for(int i = 0; i < numTables; ++i) {
- if (offset + 6 > tab.size()) {
-// qDebug("offset out of bounds");
const uchar *header = table + offset;
- ushort version = qFromBigEndian<quint16>(header);
- ushort length = qFromBigEndian<quint16>(header+2);
- ushort coverage = qFromBigEndian<quint16>(header+4);
+ if (!qSafeFromBigEndian(header, end, &version))
+ if (!qSafeFromBigEndian(header + 2, end, &length))
+ if (!qSafeFromBigEndian(header + 4, end, &coverage))
// qDebug("subtable: version=%d, coverage=%x",version, coverage);
if(version == 0 && coverage == 0x0001) {
if (offset + length > tab.size()) {
const uchar *data = table + offset + 6;
- ushort nPairs = qFromBigEndian<quint16>(data);
+ if (!qSafeFromBigEndian(data, end, &nPairs))
if(nPairs * 6 + 8 > length - 6) {
// qDebug("corrupt table!");
for(int i = 0; i < nPairs; ++i) {
- p.left_right = (((uint)qFromBigEndian<quint16>(data+off)) << 16) + qFromBigEndian<quint16>(data+off+2);
- p.adjust = QFixed(((int)(short)qFromBigEndian<quint16>(data+off+4))) / scalingFactor;
+ if (!qSafeFromBigEndian(data + off, end, &tmp))
+ p.left_right = uint(tmp) << 16;