Skip to content

Commit

Permalink
Fix specific overflow in qtextlayout (CVE-2023-32763)
Browse files Browse the repository at this point in the history
Fixes: QTBUG-113337
Pick-to: 6.5 6.5.1 6.2 5.15
Change-Id: I13579306defceaccdc0fbb1ec0e9b77c6f8d1af9
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 7b7a01c)

* asturmlechner 2023-05-23: Upstream backport to 5.15 taken from
  https://www.qt.io/blog/security-advisory-qt-svg-1
  • Loading branch information
Allan Sandfeld Jensen authored and tsdgeos committed Oct 4, 2023
1 parent 0628df4 commit a1ba7a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/gui/painting/qfixed_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include <QtGui/private/qtguiglobal_p.h>
#include "QtCore/qdebug.h"
#include "QtCore/qpoint.h"
#include <QtCore/private/qnumeric_p.h>
#include "QtCore/qsize.h"

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -182,6 +183,14 @@ Q_DECL_CONSTEXPR inline bool operator<(int i, const QFixed &f) { return i * 64 <
Q_DECL_CONSTEXPR inline bool operator>(const QFixed &f, int i) { return f.value() > i * 64; }
Q_DECL_CONSTEXPR inline bool operator>(int i, const QFixed &f) { return i * 64 > f.value(); }

inline bool qAddOverflow(QFixed v1, QFixed v2, QFixed *r)
{
int val;
bool result = add_overflow(v1.value(), v2.value(), &val);
r->setValue(val);
return result;
}

#ifndef QT_NO_DEBUG_STREAM
inline QDebug &operator<<(QDebug &dbg, const QFixed &f)
{ return dbg << f.toReal(); }
Expand Down
9 changes: 6 additions & 3 deletions src/gui/text/qtextlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2163,11 +2163,14 @@ void QTextLine::layout_helper(int maxGlyphs)
eng->maxWidth = qMax(eng->maxWidth, line.textWidth);
} else {
eng->minWidth = qMax(eng->minWidth, lbh.minw);
eng->maxWidth += line.textWidth;
if (qAddOverflow(eng->maxWidth, line.textWidth, &eng->maxWidth))
eng->maxWidth = QFIXED_MAX;
}

if (line.textWidth > 0 && item < eng->layoutData->items.size())
eng->maxWidth += lbh.spaceData.textWidth;
if (line.textWidth > 0 && item < eng->layoutData->items.size()) {
if (qAddOverflow(eng->maxWidth, lbh.spaceData.textWidth, &eng->maxWidth))
eng->maxWidth = QFIXED_MAX;
}

line.textWidth += trailingSpace;
if (lbh.spaceData.length) {
Expand Down

0 comments on commit a1ba7a9

Please sign in to comment.