aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2025-10-31 09:08:51 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2025-10-31 17:16:15 +0100
commit144ce34e846b3f732bdb003f99b1f9455425416f (patch)
tree60ba86f9202193b548162de0db2c062d3ef73291 /src
parentc7d5375714f5dc706416ea62375092f5c1214422 (diff)
Rich text: Limit size of text object
When we draw a text object, we need to store this in RAM since the QTextObjectInterface is QPainter-based. This could lead to over-allocation if the text object size was set to be very large. We use the existing image IO infrastructure for making sure allocations are within reasonable (and configurable) limits. Pick-to: 5.15 6.5 6.8 6.10 Task-number: QTBUG-141515 Change-Id: Ieae06a9e92a7bd078d22ab2314889201c2049122 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquicktextnodeengine.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp
index 461191f6d0..d000638593 100644
--- a/src/quick/items/qquicktextnodeengine.cpp
+++ b/src/quick/items/qquicktextnodeengine.cpp
@@ -12,6 +12,7 @@
#include <QtGui/qtextobject.h>
#include <QtGui/qtexttable.h>
#include <QtGui/qtextlist.h>
+#include <QtGui/qimageiohandler.h>
#include <private/qquicktext_p.h>
#include <private/qtextdocumentlayout_p.h>
@@ -435,12 +436,15 @@ void QQuickTextNodeEngine::addTextObject(const QTextBlock &block, const QPointF
}
if (image.isNull()) {
- image = QImage((size * m_devicePixelRatio).toSize(), QImage::Format_ARGB32_Premultiplied);
- image.setDevicePixelRatio(m_devicePixelRatio);
- image.fill(Qt::transparent);
- {
- QPainter painter(&image);
- handler->drawObject(&painter, QRectF({}, size), textDocument, pos, format);
+ if (QImageIOHandler::allocateImage((size * m_devicePixelRatio).toSize(),
+ QImage::Format_ARGB32_Premultiplied,
+ &image)) {
+ image.setDevicePixelRatio(m_devicePixelRatio);
+ image.fill(Qt::transparent);
+ {
+ QPainter painter(&image);
+ handler->drawObject(&painter, QRectF({}, size), textDocument, pos, format);
+ }
}
}