From 7481c148ac71e822d2a211c6055070b36275b38a Mon Sep 17 00:00:00 2001 From: Easton Pillay Date: Wed, 12 Jan 2022 15:54:12 -0600 Subject: [PATCH] Added check for maximum size of downloaded file names (#1842) --- src/AppInstallerCLICore/Workflows/DownloadFlow.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp b/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp index 06fca0ad86..c8b4c61c17 100644 --- a/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/DownloadFlow.cpp @@ -63,10 +63,11 @@ namespace AppInstaller::CLI::Workflow { // Get file name from download URI std::filesystem::path filename = GetFileNameFromURI(context.Get()->Url); + std::wstring_view installerExtension = GetInstallerFileExtension(context); - // Assuming that we find a stem value in the URI, use it. + // Assuming that we find a safe stem value in the URI, use it. // This should be extremely common, but just in case fall back to the older name style. - if (filename.has_stem()) + if (filename.has_stem() && ((filename.string().size() + installerExtension.size()) < MAX_PATH)) { filename = filename.stem(); } @@ -76,7 +77,7 @@ namespace AppInstaller::CLI::Workflow filename = Utility::ConvertToUTF16(manifest.Id + '.' + manifest.Version); } - filename += GetInstallerFileExtension(context); + filename += installerExtension; return filename; }