Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.5.0
-
None
Description
The invalid state for glyph_metrics_t is currently hardcoded as a state where either the x or y values are 100000:
struct Q_GUI_EXPORT glyph_metrics_t { ... inline bool isValid() const {return x != 100000 && y != 100000;} ... }
However, all variants of QFontMetrics::boundingRect() return a QRect created from a glyph_metrics_t without bothering to check if it's valid first:
QRect QFontMetrics::boundingRect(const QString &text) const { if (text.size() == 0) return QRect(); QStackTextEngine layout(text, QFont(d.data())); layout.itemize(); glyph_metrics_t gm = layout.boundingBox(0, text.size()); // no validity check here return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height)); }
This lead to an out of memory error trying to render a 100000 by 100000 image of a glyph in a production code base.
Returning a 100000 by 100000 QRect on error would be fine if it were documented to return such, but the "100000" is buried deep and undocumented in the QT source. So it would be nice to either 1) document that a 100000 by 100000 QRect should be interpreted as an error, or 2) add handling to boundingRect() to return, e.g., a 0x0 QRect or a proper error code upon error.