|
| 1 | +From ccf4cbf309f7d1da4df07e2239e5b674b9534bce Mon Sep 17 00:00:00 2001 |
| 2 | +From: jykanase < [email protected]> |
| 3 | +Date: Fri, 13 Jun 2025 14:00:19 +0000 |
| 4 | +Subject: [PATCH] CVE-2025-30348.patch |
| 5 | + |
| 6 | +Upstream Patch Reference: https://codereview.qt-project.org/c/qt/qtbase/+/581442/1/src/xml/dom/qdom.cpp#3643 |
| 7 | +--- |
| 8 | + src/xml/dom/qdom.cpp | 60 ++++++++++++++------------------------------ |
| 9 | + 1 file changed, 19 insertions(+), 41 deletions(-) |
| 10 | + |
| 11 | +diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp |
| 12 | +index dd6916f9..cb33b78c 100644 |
| 13 | +--- a/src/xml/dom/qdom.cpp |
| 14 | ++++ b/src/xml/dom/qdom.cpp |
| 15 | +@@ -4159,56 +4159,34 @@ static QString encodeText(const QString &str, |
| 16 | + const QTextCodec *const codec = s.codec(); |
| 17 | + Q_ASSERT(codec); |
| 18 | + #endif |
| 19 | +- QString retval(str); |
| 20 | +- int len = retval.length(); |
| 21 | +- int i = 0; |
| 22 | ++ const qsizetype len = str.size(); |
| 23 | ++ QString retval; |
| 24 | ++ retval.reserve(len * 1.2); |
| 25 | ++ qsizetype i = 0; |
| 26 | + |
| 27 | + while (i < len) { |
| 28 | +- const QChar ati(retval.at(i)); |
| 29 | ++ const QChar ati(str.at(i)); |
| 30 | + |
| 31 | + if (ati == QLatin1Char('<')) { |
| 32 | +- retval.replace(i, 1, QLatin1String("<")); |
| 33 | +- len += 3; |
| 34 | +- i += 4; |
| 35 | ++ retval.append(QLatin1String("<")); |
| 36 | + } else if (encodeQuotes && (ati == QLatin1Char('"'))) { |
| 37 | +- retval.replace(i, 1, QLatin1String(""")); |
| 38 | +- len += 5; |
| 39 | +- i += 6; |
| 40 | ++ retval.append(QLatin1String(""")); |
| 41 | + } else if (ati == QLatin1Char('&')) { |
| 42 | +- retval.replace(i, 1, QLatin1String("&")); |
| 43 | +- len += 4; |
| 44 | +- i += 5; |
| 45 | +- } else if (ati == QLatin1Char('>') && i >= 2 && retval[i - 1] == QLatin1Char(']') && retval[i - 2] == QLatin1Char(']')) { |
| 46 | +- retval.replace(i, 1, QLatin1String(">")); |
| 47 | +- len += 3; |
| 48 | +- i += 4; |
| 49 | ++ retval.append(QLatin1String("&")); |
| 50 | ++ } else if (ati == QLatin1Char('>') && i >= 2 && str.at(i - 1) == QLatin1Char(']') && str.at(i - 2) == QLatin1Char(']')) { |
| 51 | ++ retval.append(QLatin1String(">")); |
| 52 | + } else if (performAVN && |
| 53 | +- (ati == QChar(0xA) || |
| 54 | +- ati == QChar(0xD) || |
| 55 | +- ati == QChar(0x9))) { |
| 56 | ++ (ati == QLatin1Char(0xA) || |
| 57 | ++ ati == QLatin1Char(0xD) || |
| 58 | ++ ati == QLatin1Char(0x9))) { |
| 59 | + const QString replacement(QLatin1String("&#x") + QString::number(ati.unicode(), 16) + QLatin1Char(';')); |
| 60 | +- retval.replace(i, 1, replacement); |
| 61 | +- i += replacement.length(); |
| 62 | +- len += replacement.length() - 1; |
| 63 | +- } else if (encodeEOLs && ati == QChar(0xD)) { |
| 64 | +- retval.replace(i, 1, QLatin1String("
")); // Replace a single 0xD with a ref for 0xD |
| 65 | +- len += 4; |
| 66 | +- i += 5; |
| 67 | ++ retval.append(replacement); |
| 68 | ++ } else if (encodeEOLs && ati == QLatin1Char(0xD)) { |
| 69 | ++ retval.append(QLatin1String("
")); // Replace a single 0xD with a ref for 0xD |
| 70 | + } else { |
| 71 | +-#if QT_CONFIG(textcodec) |
| 72 | +- if(codec->canEncode(ati)) |
| 73 | +- ++i; |
| 74 | +- else |
| 75 | +-#endif |
| 76 | +- { |
| 77 | +- // We have to use a character reference to get it through. |
| 78 | +- const ushort codepoint(ati.unicode()); |
| 79 | +- const QString replacement(QLatin1String("&#x") + QString::number(codepoint, 16) + QLatin1Char(';')); |
| 80 | +- retval.replace(i, 1, replacement); |
| 81 | +- i += replacement.length(); |
| 82 | +- len += replacement.length() - 1; |
| 83 | +- } |
| 84 | +- } |
| 85 | ++ retval.append(ati); |
| 86 | ++ } |
| 87 | ++ ++i; |
| 88 | + } |
| 89 | + |
| 90 | + return retval; |
| 91 | +-- |
| 92 | +2.45.2 |
| 93 | + |
0 commit comments