From ada927d19a9d0e2c6bc23b3a08b9bf05a985d685 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 17 Jun 2025 14:37:47 +0200 Subject: windeployqt: Fix access of invalid iterators crash We must not use a range based loop here as the container might be changed inside the loop which will invalidate the iterators which in turn might lead to a crash. While at it the QFileInfo used to obtain the binary's path was moved out of the loop as a small cleanup. Fixes: QTBUG-137763 Pick-to: 6.10 6.9 6.8 Change-Id: I86fb8b683fb98a897d0059ef1dc869e26b2c213f Reviewed-by: Joerg Bornemann --- src/tools/windeployqt/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tools/windeployqt/main.cpp b/src/tools/windeployqt/main.cpp index 496fa512621..7d3808d301a 100644 --- a/src/tools/windeployqt/main.cpp +++ b/src/tools/windeployqt/main.cpp @@ -1490,10 +1490,13 @@ static DeployResult deploy(const Options &options, const QMap } } + const QFileInfo fi(options.binaries.first()); + const QString canonicalBinPath = fi.canonicalPath(); // Also check Qt dependencies of "local non Qt dependencies" (dlls located in the same folder) - for (const QString &nonQtLib : dependentNonQtLibs) { - const QFileInfo fi(options.binaries.first()); - const QString path = fi.canonicalPath() + u'/' + nonQtLib; + // Index based loop as container might be changed which invalidates iterators + for (qsizetype i = 0; i < dependentNonQtLibs.size(); ++i) { + const QString nonQtLib = dependentNonQtLibs.at(i); + const QString path = canonicalBinPath + u'/' + nonQtLib; if (!QFileInfo::exists(path)) continue; -- cgit v1.2.3