qt6-bb10/tests/auto/corelib/serialization/qxmlstream
Ahmad Samir 6326bec46a QXmlStreamReader: make fastScanName() indicate parsing status to callers
This fixes a crash while parsing an XML file with garbage data, the file
starts with '<' then garbage data:
- The loop in the parse() keeps iterating until it hits "case 262:",
  which calls fastScanName()
- fastScanName() iterates over the text buffer scanning for the
  attribute name (e.g. "xml:lang"), until it finds ':'
- Consider a Value val, fastScanName() is called on it, it would set
  val.prefix to a number > val.len, then it would hit the 4096 condition
  and return (returned 0, now it returns the equivalent of
  std::null_opt), which means that val.len doesn't get modified, making
  it smaller than val.prefix
- The code would try constructing an XmlStringRef with negative length,
  which would hit an assert in one of QStringView's constructors

Add an assert to the XmlStringRef constructor.

Add unittest based on the file from the bug report.

Later on I will replace FastScanNameResult with std::optional<qsizetype>
(std::optional is C++17, which isn't required by Qt 5.15, and we want to
backport this fix).

Credit to OSS-Fuzz.

Fixes: QTBUG-109781
Fixes: QTBUG-114829
Pick-to: 6.6 6.5 6.2 5.15
Change-Id: I455a5eeb47870c2ac9ffd0cbcdcd99c1ae2dd374
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2023-06-28 00:11:21 +03:00
..
XML-Test-Suite Remove execute permission from XML files 2022-01-17 18:47:22 +01:00
data Correct prefix reported for end element in QXmlStreamReader 2021-04-20 03:03:51 +02:00
.gitattributes Create corelib/serialization and move existing file formats into it 2018-01-26 20:59:50 +00:00
.gitignore Create corelib/serialization and move existing file formats into it 2018-01-26 20:59:50 +00:00
CMakeLists.txt Move QZipReader/Writer from QtGui to QtCore 2023-04-26 12:01:05 +02:00
XML-Test-Suite-LICENSE.txt Create corelib/serialization and move existing file formats into it 2018-01-26 20:59:50 +00:00
qc14n.h qc14n.h: general cleanup 2023-05-01 22:52:22 +03:00
setupSuite.sh Use SPDX license identifiers 2022-05-16 16:37:38 +02:00
tst_qxmlstream.cpp QXmlStreamReader: make fastScanName() indicate parsing status to callers 2023-06-28 00:11:21 +03:00