summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextengine_p.h
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2010-08-05 09:21:03 (GMT)
committerJiang Jiang <jiang.jiang@nokia.com>2010-08-05 12:10:56 (GMT)
commit05bb249c2ad3ee15eb205a806f8546c105683096 (patch)
tree77b111450fa1325caaea0cb17425050032d769a7 /src/gui/text/qtextengine_p.h
parent15505360dc8e8b8f1343bba6fd3e5a9c95718d30 (diff)
downloadQt-05bb249c2ad3ee15eb205a806f8546c105683096.zip
Qt-05bb249c2ad3ee15eb205a806f8546c105683096.tar.gz
Qt-05bb249c2ad3ee15eb205a806f8546c105683096.tar.bz2
Fix QTextEngine overflow caused by extremely long text
Internally, QTextEngine use int to calculate most of the layout data required. If a string longer than 2^24 is passed into either QTextEngine or classes using it (QStackTextEngine, QPainter, QFontMetrics, etc.), overflow will happen because the memory size required to allocate for layout will become too large for int to handle. This patch will prevent these cases and add error handling mechanism for relevant code. Task-number: QT-3658 Reviewed-by: Eskil Abrahamsen Blomfeldt
Diffstat (limited to 'src/gui/text/qtextengine_p.h')
-rw-r--r--src/gui/text/qtextengine_p.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h
index e623fa5..4cbe81f 100644
--- a/src/gui/text/qtextengine_p.h
+++ b/src/gui/text/qtextengine_p.h
@@ -416,6 +416,11 @@ class QTextFormatCollection;
class Q_GUI_EXPORT QTextEngine {
public:
+ enum LayoutState {
+ LayoutEmpty,
+ InLayout,
+ LayoutFailed,
+ };
struct LayoutData {
LayoutData(const QString &str, void **stack_memory, int mem_size);
LayoutData();
@@ -428,11 +433,11 @@ public:
QGlyphLayout glyphLayout;
mutable int used;
uint hasBidi : 1;
- uint inLayout : 1;
+ uint layoutState : 2;
uint memory_on_stack : 1;
bool haveCharAttributes;
QString string;
- void reallocate(int totalGlyphs);
+ bool reallocate(int totalGlyphs);
};
QTextEngine(LayoutData *data);
@@ -520,9 +525,10 @@ public:
return layoutData->glyphLayout.mid(si->glyph_data_offset, si->num_glyphs);
}
- inline void ensureSpace(int nGlyphs) const {
+ inline bool ensureSpace(int nGlyphs) const {
if (layoutData->glyphLayout.numGlyphs - layoutData->used < nGlyphs)
- layoutData->reallocate((((layoutData->used + nGlyphs)*3/2 + 15) >> 4) << 4);
+ return layoutData->reallocate((((layoutData->used + nGlyphs)*3/2 + 15) >> 4) << 4);
+ return true;
}
void freeMemory();