qtdeclarative-5.15.18-CVE-2025-12385.patch 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. From f78bc0b2c6884fd730bf34a931870d67936cf01d Mon Sep 17 00:00:00 2001
  2. From: Albert Astals Cid <aacid@kde.org>
  3. Date: Sun, 7 Dec 2025 11:44:35 +0100
  4. Subject: [PATCH] Increase robustness of <img> tag in Text component
  5. For Text.StyledText, there was no protection against <img> tags
  6. with very large widths or heights. This could cause an application
  7. to spend a very long time processing a layout and sometimes crash
  8. if the size was too large.
  9. We reuse the internal coord limit in QPainter as our maximum size
  10. here, similar to what we do in Qt Svg for instance.
  11. For Text.RichText, there were no issues in release builds, but in
  12. debug builds, you could trigger an overflow assert when rounding
  13. the number if it exceeded INT_MAX. For this, we simply cap the
  14. width and height at INT_MAX.
  15. Fixes: QTBUG-141515
  16. Pick-to: 5.15
  17. Change-Id: I4bcba16158f5f495a0de38963316effc4c46aae1
  18. Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
  19. (cherry picked from commit 4aaf9bf21f7cc69d73066785e254b664fcc82025)
  20. Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
  21. (cherry picked from commit 907c7ceb7b27586039262567273efd5ec79e6202)
  22. (cherry picked from commit c4b74f27058b302a101befc2c1967f8c00b41be7)
  23. This is actually a manual patch based on
  24. https://download.qt.io/official_releases/qt/6.5/CVE-2025-12385-qtdeclarative-6.5-0002.diff
  25. ---
  26. src/quick/items/qquicktextdocument.cpp | 4 ++--
  27. src/quick/util/qquickstyledtext.cpp | 19 +++++++++++++++++--
  28. 2 files changed, 19 insertions(+), 4 deletions(-)
  29. diff --git a/src/quick/items/qquicktextdocument.cpp b/src/quick/items/qquicktextdocument.cpp
  30. index 021bbca0f6..67ed63d0de 100644
  31. --- a/src/quick/items/qquicktextdocument.cpp
  32. +++ b/src/quick/items/qquicktextdocument.cpp
  33. @@ -138,9 +138,9 @@ QSizeF QQuickTextDocumentWithImageResources::intrinsicSize(
  34. if (format.isImageFormat()) {
  35. QTextImageFormat imageFormat = format.toImageFormat();
  36. - const int width = qRound(imageFormat.width());
  37. + int width = qRound(qBound(qreal(INT_MIN), imageFormat.width(), qreal(INT_MAX)));
  38. const bool hasWidth = imageFormat.hasProperty(QTextFormat::ImageWidth) && width > 0;
  39. - const int height = qRound(imageFormat.height());
  40. + const int height = qRound(qBound(qreal(INT_MIN), imageFormat.height(), qreal(INT_MAX)));
  41. const bool hasHeight = imageFormat.hasProperty(QTextFormat::ImageHeight) && height > 0;
  42. QSizeF size(width, height);
  43. diff --git a/src/quick/util/qquickstyledtext.cpp b/src/quick/util/qquickstyledtext.cpp
  44. index a25af90414..120a2593d3 100644
  45. --- a/src/quick/util/qquickstyledtext.cpp
  46. +++ b/src/quick/util/qquickstyledtext.cpp
  47. @@ -45,6 +45,11 @@
  48. #include <qmath.h>
  49. #include "qquickstyledtext_p.h"
  50. #include <QQmlContext>
  51. +#include <QtGui/private/qoutlinemapper_p.h>
  52. +
  53. +#ifndef QQUICKSTYLEDPARSER_COORD_LIMIT
  54. +# define QQUICKSTYLEDPARSER_COORD_LIMIT QT_RASTER_COORD_LIMIT
  55. +#endif
  56. Q_LOGGING_CATEGORY(lcStyledText, "qt.quick.styledtext")
  57. @@ -694,9 +699,19 @@ void QQuickStyledTextPrivate::parseImageAttributes(const QChar *&ch, const QStri
  58. if (attr.first == QLatin1String("src")) {
  59. image->url = QUrl(attr.second.toString());
  60. } else if (attr.first == QLatin1String("width")) {
  61. - image->size.setWidth(attr.second.toString().toInt());
  62. + bool ok;
  63. + int v = attr.second.toString().toInt(&ok);
  64. + if (ok && v <= QQUICKSTYLEDPARSER_COORD_LIMIT)
  65. + image->size.setWidth(v);
  66. + else
  67. + qCWarning(lcStyledText) << "Invalid width provided for <img>";
  68. } else if (attr.first == QLatin1String("height")) {
  69. - image->size.setHeight(attr.second.toString().toInt());
  70. + bool ok;
  71. + int v = attr.second.toString().toInt(&ok);
  72. + if (ok && v <= QQUICKSTYLEDPARSER_COORD_LIMIT)
  73. + image->size.setHeight(v);
  74. + else
  75. + qCWarning(lcStyledText) << "Invalid height provided for <img>";
  76. } else if (attr.first == QLatin1String("align")) {
  77. if (attr.second.toString() == QLatin1String("top")) {
  78. image->align = QQuickStyledTextImgTag::Top;
  79. --
  80. 2.52.0