QXmlStreamReader: Raise error on unexpected tokens
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Sun, 28 Apr 2024 18:48:02 +0000 (20:48 +0200)
committerThorsten Alteholz <debian@alteholz.de>
Sun, 28 Apr 2024 18:48:02 +0000 (20:48 +0200)
commit9ddde2927413f6ce90994d6b90c48f67e41fc267
treeafeb536b71574d8811f8cf64199ce82cef5b418d
parentc82a4b05eb2bdf2d9be9e90caefdfde4b07e8f76
QXmlStreamReader: Raise error on unexpected tokens

Origin: upstream, https://download.qt.io/official_releases/qt/5.15/CVE-2023-38197-qtbase-5.15.diff
Last-Update: 2023-07-15

QXmlStreamReader accepted multiple DOCTYPE elements, containing DTD
fragments in the XML prolog, and in the XML body.
Well-formed but invalid XML files - with multiple DTD fragments in
prolog and body, combined with recursive entity expansions - have
caused infinite loops in QXmlStreamReader.

This patch implements a token check in QXmlStreamReader.
A stream is allowed to start with an XML prolog. StartDocument
and DOCTYPE elements are only allowed in this prolog, which
may also contain ProcessingInstruction and Comment elements.
As soon as anything else is seen, the prolog ends.
After that, the prolog-specific elements are treated as unexpected.
Furthermore, the prolog can contain at most one DOCTYPE element.

Update the documentation to reflect the new behavior.
Add an autotest that checks the new error cases are correctly detected,
and no error is raised for legitimate input.

The original OSS-Fuzz files (see bug reports) are not included in this
patch for file size reasons. They have been tested manually. Each of
them has more than one DOCTYPE element, causing infinite loops in
recursive entity expansions. The newly implemented functionality
detects those invalid DTD fragments. By raising an error, it aborts
stream reading before an infinite loop occurs.

Thanks to OSS-Fuzz for finding this.

Gbp-Pq: Name CVE-2023-38197.diff
src/corelib/serialization/qxmlstream.cpp
src/corelib/serialization/qxmlstream_p.h
tests/auto/corelib/serialization/qxmlstream/tokenError/dtdInBody.xml [new file with mode: 0644]
tests/auto/corelib/serialization/qxmlstream/tokenError/multipleDtd.xml [new file with mode: 0644]
tests/auto/corelib/serialization/qxmlstream/tokenError/wellFormed.xml [new file with mode: 0644]
tests/auto/corelib/serialization/qxmlstream/tst_qxmlstream.cpp