Skip to content

Commit 9520674

Browse files
net147Qt by Nokia
authored andcommitted
QGLGlyphCache: Fix texture buffer overrun
The QGLGlyphCache::cacheGlyphs function reallocates a larger texture when there is no more room to insert a newly rendered glyph. However, the glyph width used to check whether reallocation is needed is not the same as the actual glyph image width and may be less. When the glyph image is then copied into the texture, a buffer overrun may occur. Task-number: QTBUG-23584 Change-Id: I71d6cd987b7519e5235109c14a5a35e452332417 Reviewed-by: Friedemann Kleint <[email protected]> Reviewed-by: Andy Shaw <[email protected]> Reviewed-by: Jiang Jiang <[email protected]>
1 parent 1b3a74e commit 9520674

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/opengl/qpaintengine_opengl.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4799,8 +4799,13 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine,
47994799
if (it == cache->constEnd()) {
48004800
// render new glyph and put it in the cache
48014801
glyph_metrics_t metrics = fontEngine->boundingBox(glyphs[i]);
4802-
int glyph_width = qRound(metrics.width.toReal())+2;
4803-
int glyph_height = qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal())+2;
4802+
QImage glyph_im(fontEngine->alphaMapForGlyph(glyphs[i]));
4803+
int glyph_width = glyph_im.width();
4804+
int glyph_height = qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal()) + 2;
4805+
Q_ASSERT(glyph_width >= 0);
4806+
// pad the glyph width to an even number
4807+
if (glyph_width % 2 != 0)
4808+
++glyph_width;
48044809

48054810
if (font_tex->x_offset + glyph_width + x_margin > font_tex->width) {
48064811
int strip_height = qt_next_power_of_two(qRound(fontEngine->ascent().toReal() + fontEngine->descent().toReal())+2);
@@ -4834,13 +4839,6 @@ void QGLGlyphCache::cacheGlyphs(QGLContext *context, QFontEngine *fontEngine,
48344839
}
48354840
}
48364841

4837-
QImage glyph_im(fontEngine->alphaMapForGlyph(glyphs[i]));
4838-
glyph_width = glyph_im.width();
4839-
Q_ASSERT(glyph_width >= 0);
4840-
// pad the glyph width to an even number
4841-
if (glyph_width%2 != 0)
4842-
++glyph_width;
4843-
48444842
QGLGlyphCoord *qgl_glyph = new QGLGlyphCoord;
48454843
qgl_glyph->x = qreal(font_tex->x_offset) / font_tex->width;
48464844
qgl_glyph->y = qreal(font_tex->y_offset) / font_tex->height;

0 commit comments

Comments
 (0)