QtQml: Reject qrc URLs that can't be represented as local files
QQmlFile::urlToLocalFileOrQrc() builds the qrc lookup path from
QUrl::path(), which defaults to FullyDecoded. That turns a
percent-encoded slash (%2F) into a real directory separator and a
percent-encoded NUL (%00) into a literal NUL character, so a path
segment meant to stay opaque can reach into a subdirectory of the
resource tree it was never meant to expose.
qtbase's 88e3ceb05106d69746fb9d0528b4c4f8df417e9a closed this hole for
QUrl::toLocalFile(), which file:// URLs go through, but the qrc branch
here never applied the same check.
Pass QUrlDecodeForLocalFile (qurl_p.h) to QUrl::path() for the qrc
branch, the same flag toLocalFile() uses internally. An empty result is
ambiguous between an empty path (safe) and a rejected one (unsafe), so
only fall back to the cheap QUrl::PrettyDecoded check to tell them apart
when that happens.
Add urlToLocalFileOrQrcUnsafe() to tst_qqmlfile.cpp, mirroring
tst_QUrl::toLocalFileUnsafe() row for row. The existing encoded- subdir
rows in tst_qquickloader.cpp and tst_qqmltypeloader.cpp now pass on
platforms that embed test data as qrc resources (Android, OHOS, iOS,
WASM) too, instead of silently loading the wrong file or failing with
the wrong error.
[ChangeLog][QtQml][Important Behavior Changes] qrc: URLs whose paths
contain a percent-encoded slash (%2F), a percent-encoded NUL (%00), an
encoded byte that isn't valid UTF-8, or, on Windows, a percent-encoded
backslash (%5C), cannot be loaded anymore. Such sequences were
previously decoded into real directory separators or characters within
the resource tree, so an escaped path segment could reach into a
subdirectory it was never meant to expose.
Amends 26a29f61dcf6b2d19efc4e63b3d518d8d7337343.
Fixes: QTBUG-151292
Fixes: QTBUG-151229
Fixes: QTBUG-151230
Fixes: QTBUG-151231
Change-Id: I76d2a035ea28256955261d2d905358af8b2b7669
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>