@samitouri / QOSAMI-WSL / commits / c3f59f8b

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

Blue committed Jun 13, 2025 at 17:21 UTC c3f59f8b128e146ee8e9e79042ad592d5c938612
4 files changed +44 -3
src/windows/common/Distribution.cpp
+2 -1
@@ -285,7 +285,8 @@ void wsl::windows::common::distribution::LegacyInstallViaGithub(const Distributi
285
286 wslutil::PrintMessage(Localization::MessageDownloading(distro.FriendlyName.c_str()), stdout);
287
288 - const auto downloadPath = wslutil::DownloadFile(*downloadUrl);
288 + // Note: The appx extensions is required for the installation to succeed.
289 + const auto downloadPath = wslutil::DownloadFile(*downloadUrl, distro.Name + L".appx");
290 auto deleteFile =
291 wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&] { THROW_IF_WIN32_BOOL_FALSE(DeleteFileW(downloadPath.c_str())); });
292
src/windows/common/WslInstall.cpp
+1 -1
@@ -300,7 +300,7 @@ std::pair<std::wstring, GUID> WslInstall::InstallModernDistribution(
300 else
301 {
302 PrintMessage(Localization::MessageDownloading(distribution.FriendlyName.c_str()), stdout);
303 - installPath = DownloadFile(downloadInfo->Url);
303 + installPath = DownloadFile(downloadInfo->Url, distribution.Name + L".wsl");
304 fileDownloaded = true;
305 }
306
src/windows/common/wslutil.h
+1 -1
@@ -82,7 +82,7 @@ std::wstring ConstructPipePath(_In_ std::wstring_view PipeName);
82
83 GUID CreateV5Uuid(const GUID& namespaceGuid, const std::span<const std::byte> name);
84
85 -std::wstring DownloadFile(std::wstring_view Url, std::wstring Filename = L"");
85 +std::wstring DownloadFile(std::wstring_view Url, std::wstring Filename);
86
87 [[nodiscard]] HANDLE DuplicateHandleFromCallingProcess(_In_ HANDLE handleInTarget);
88
test/windows/UnitTests.cpp
+40
@@ -5269,6 +5269,46 @@ Error code: Wsl/InstallDistro/E_UNEXPECTED\r\n",
5269 Error code: Wsl/InstallDistro/WSL_E_INVALID_JSON\r\n",
5270 L"");
5271 }
5272 +
5273 + // Validate that url parameters are correctly handled.
5274 + {
5275 + constexpr auto tarEndpoint = L"http://127.0.0.1:6667/";
5276 +
5277 + UniqueWebServer fileServer(tarEndpoint, std::filesystem::path(g_testDistroPath));
5278 +
5279 + wil::unique_handle tarHandle{CreateFile(g_testDistroPath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr)};
5280 + VERIFY_IS_TRUE(!!tarHandle);
5281 +
5282 + auto manifest = std::format(
5283 + R"({{
5284 + "ModernDistributions": {{
5285 + "test": [
5286 + {{
5287 + "Name": "test-url-download",
5288 + "FriendlyName": "FriendlyName",
5289 + "Default": true,
5290 + "Amd64Url": {{
5291 + "Url": "{}/distro.tar?foo=bar&key=value",
5292 + "Sha256": "{}"
5293 + }}
5294 + }}
5295 + ]
5296 + }}}})",
5297 + tarEndpoint,
5298 + tarHash);
5299 +
5300 + auto restore = SetManifest(manifest);
5301 +
5302 + auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, []() { UnregisterDistribution(L"test-url-download"); });
5303 +
5304 + auto [output, error] = LxsstuLaunchWslAndCaptureOutput(L"--install --no-launch test-url-download");
5305 + VERIFY_ARE_EQUAL(
5306 + output,
5307 + L"Downloading: FriendlyName\r\nInstalling: FriendlyName\r\nDistribution successfully installed. It can be "
5308 + L"launched via 'wsl.exe -d test-url-download'\r\n");
5309 +
5310 + VERIFY_ARE_EQUAL(error, L"");
5311 + }
5312 }
5313
5314 TEST_METHOD(ModernInstallEndToEnd)