0005-Fix-specific-overflow-in-qtextlayout.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From 693a617236d37e12798013c75d51fd02dd1e1963 Mon Sep 17 00:00:00 2001
  2. From: Allan Sandfeld Jensen <allan.jensen@qt.io>
  3. Date: Fri, 5 May 2023 09:51:32 +0200
  4. Subject: [PATCH] Fix specific overflow in qtextlayout
  5. Adds qAddOverflow and qMulOverflow definitions to QFixed
  6. Fixes: QTBUG-113337
  7. Pick-to: 6.5 6.5.1 6.2 5.15
  8. Change-Id: I13579306defceaccdc0fbb1ec0e9b77c6f8d1af9
  9. Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
  10. Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  11. Fixes: https://security-tracker.debian.org/tracker/CVE-2023-32763
  12. Upstream: https://github.com/qt/qtbase/commit/7b7a01c266b507636eab51a36328c7c72d82d93c
  13. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  14. ---
  15. src/gui/painting/qfixed_p.h | 17 +++++++++++++++++
  16. src/gui/text/qtextlayout.cpp | 9 ++++++---
  17. 2 files changed, 23 insertions(+), 3 deletions(-)
  18. diff --git a/src/gui/painting/qfixed_p.h b/src/gui/painting/qfixed_p.h
  19. index f3718a097e5..c0a13d057f5 100644
  20. --- a/src/gui/painting/qfixed_p.h
  21. +++ b/src/gui/painting/qfixed_p.h
  22. @@ -18,6 +18,7 @@
  23. #include <QtGui/private/qtguiglobal_p.h>
  24. #include "QtCore/qdebug.h"
  25. #include "QtCore/qpoint.h"
  26. +#include "QtCore/qnumeric.h"
  27. #include "QtCore/qsize.h"
  28. QT_BEGIN_NAMESPACE
  29. @@ -136,6 +137,22 @@ constexpr inline QFixed operator+(uint i, QFixed d) { return d+i; }
  30. constexpr inline QFixed operator-(uint i, QFixed d) { return -(d-i); }
  31. // constexpr inline QFixed operator*(qreal d, QFixed d2) { return d2*d; }
  32. +inline bool qAddOverflow(QFixed v1, QFixed v2, QFixed *r)
  33. +{
  34. + int val;
  35. + bool result = qAddOverflow(v1.value(), v2.value(), &val);
  36. + r->setValue(val);
  37. + return result;
  38. +}
  39. +
  40. +inline bool qMulOverflow(QFixed v1, QFixed v2, QFixed *r)
  41. +{
  42. + int val;
  43. + bool result = qMulOverflow(v1.value(), v2.value(), &val);
  44. + r->setValue(val);
  45. + return result;
  46. +}
  47. +
  48. #ifndef QT_NO_DEBUG_STREAM
  49. inline QDebug &operator<<(QDebug &dbg, QFixed f)
  50. { return dbg << f.toReal(); }
  51. diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
  52. index 2009dd3d0bb..1844f777b4e 100644
  53. --- a/src/gui/text/qtextlayout.cpp
  54. +++ b/src/gui/text/qtextlayout.cpp
  55. @@ -2105,9 +2105,12 @@ found:
  56. eng->maxWidth = qMax(eng->maxWidth, line.textWidth);
  57. } else {
  58. eng->minWidth = qMax(eng->minWidth, lbh.minw);
  59. - eng->layoutData->currentMaxWidth += line.textWidth;
  60. - if (!manuallyWrapped)
  61. - eng->layoutData->currentMaxWidth += lbh.spaceData.textWidth;
  62. + if (qAddOverflow(eng->layoutData->currentMaxWidth, line.textWidth, &eng->layoutData->currentMaxWidth))
  63. + eng->layoutData->currentMaxWidth = QFIXED_MAX;
  64. + if (!manuallyWrapped) {
  65. + if (qAddOverflow(eng->layoutData->currentMaxWidth, lbh.spaceData.textWidth, &eng->layoutData->currentMaxWidth))
  66. + eng->layoutData->currentMaxWidth = QFIXED_MAX;
  67. + }
  68. eng->maxWidth = qMax(eng->maxWidth, eng->layoutData->currentMaxWidth);
  69. if (manuallyWrapped)
  70. eng->layoutData->currentMaxWidth = 0;
  71. --
  72. 2.46.0