Don't try to create invalid file names if the distribution download url contains parameters (#13109)

This commit is contained in:
Blue 2025-06-13 17:21:28 -07:00 committed by GitHub
parent 02ca6d3d2d
commit c3f59f8b12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 3 deletions

View File

@ -285,7 +285,8 @@ void wsl::windows::common::distribution::LegacyInstallViaGithub(const Distributi
wslutil::PrintMessage(Localization::MessageDownloading(distro.FriendlyName.c_str()), stdout);
const auto downloadPath = wslutil::DownloadFile(*downloadUrl);
// Note: The appx extensions is required for the installation to succeed.
const auto downloadPath = wslutil::DownloadFile(*downloadUrl, distro.Name + L".appx");
auto deleteFile =
wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&] { THROW_IF_WIN32_BOOL_FALSE(DeleteFileW(downloadPath.c_str())); });

View File

@ -300,7 +300,7 @@ std::pair<std::wstring, GUID> WslInstall::InstallModernDistribution(
else
{
PrintMessage(Localization::MessageDownloading(distribution.FriendlyName.c_str()), stdout);
installPath = DownloadFile(downloadInfo->Url);
installPath = DownloadFile(downloadInfo->Url, distribution.Name + L".wsl");
fileDownloaded = true;
}

View File

@ -82,7 +82,7 @@ std::wstring ConstructPipePath(_In_ std::wstring_view PipeName);
GUID CreateV5Uuid(const GUID& namespaceGuid, const std::span<const std::byte> name);
std::wstring DownloadFile(std::wstring_view Url, std::wstring Filename = L"");
std::wstring DownloadFile(std::wstring_view Url, std::wstring Filename);
[[nodiscard]] HANDLE DuplicateHandleFromCallingProcess(_In_ HANDLE handleInTarget);

View File

@ -5269,6 +5269,46 @@ Error code: Wsl/InstallDistro/E_UNEXPECTED\r\n",
Error code: Wsl/InstallDistro/WSL_E_INVALID_JSON\r\n",
L"");
}
// Validate that url parameters are correctly handled.
{
constexpr auto tarEndpoint = L"http://127.0.0.1:6667/";
UniqueWebServer fileServer(tarEndpoint, std::filesystem::path(g_testDistroPath));
wil::unique_handle tarHandle{CreateFile(g_testDistroPath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr)};
VERIFY_IS_TRUE(!!tarHandle);
auto manifest = std::format(
R"({{
"ModernDistributions": {{
"test": [
{{
"Name": "test-url-download",
"FriendlyName": "FriendlyName",
"Default": true,
"Amd64Url": {{
"Url": "{}/distro.tar?foo=bar&key=value",
"Sha256": "{}"
}}
}}
]
}}}})",
tarEndpoint,
tarHash);
auto restore = SetManifest(manifest);
auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, []() { UnregisterDistribution(L"test-url-download"); });
auto [output, error] = LxsstuLaunchWslAndCaptureOutput(L"--install --no-launch test-url-download");
VERIFY_ARE_EQUAL(
output,
L"Downloading: FriendlyName\r\nInstalling: FriendlyName\r\nDistribution successfully installed. It can be "
L"launched via 'wsl.exe -d test-url-download'\r\n");
VERIFY_ARE_EQUAL(error, L"");
}
}
TEST_METHOD(ModernInstallEndToEnd)