diff options
| author | Ivan Solovev <ivan.solovev@qt.io> | 2025-03-21 11:55:38 +0100 |
|---|---|---|
| committer | Ivan Solovev <ivan.solovev@qt.io> | 2025-03-25 13:41:31 +0100 |
| commit | 4b8659ebf689b79ac88f5935ad662a604f0c8bea (patch) | |
| tree | 2dc1f84cc7b7d76561c7baeaa8d9caffbb490e83 /src/corelib/serialization/qxmlstream.cpp | |
| parent | 74e5a51babe0a133ce0fe9b907ef77cc606fbcb9 (diff) | |
QXmlStreamReader::addData: lock encoding for QLatin1 case
This fixes a bug when addData() is used to add a full Latin1-encoded
XML document with a proper "encoding" attribute.
Once addData() is called, it immediately converts the data to UTF-8.
However, if the encoding is not locked, the parser will later see
the "encoding" attribute, and try to interpret the data according
to the specified encoding.
The QXSR(QASV) constructor is not affected, because it already locks
the encoding.
Add a unit-test for the issue.
Amends 6bc227a06a0d1392d220aa79ddb1cdc145d4f76e.
[ChangeLog][QtCore][QXmlStreamReader] Fixed a bug when calling
addData() with a Latin1-encoded string containing a full XML document
with an encoding attribute, could result in incorrect parsing of this
document.
Fixes: QTBUG-135033
Pick-to: 6.9 6.8 6.5
Change-Id: I9a35d16d743050ea4feccab3d1336747ce0abff4
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/serialization/qxmlstream.cpp')
| -rw-r--r-- | src/corelib/serialization/qxmlstream.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/corelib/serialization/qxmlstream.cpp b/src/corelib/serialization/qxmlstream.cpp index 50f87900161..182f3d7e1e8 100644 --- a/src/corelib/serialization/qxmlstream.cpp +++ b/src/corelib/serialization/qxmlstream.cpp @@ -572,6 +572,7 @@ void QXmlStreamReader::addData(QAnyStringView data) } else if constexpr (std::is_same_v<decltype(data), QLatin1StringView>) { // Conversion to a QString is required, to avoid breaking // pre-existing (before porting to QAnyStringView) behavior. + d->lockEncoding = true; if (!d->decoder.isValid()) d->decoder = QStringDecoder(QStringDecoder::Utf8); addDataImpl(QString::fromLatin1(data).toUtf8()); |
