From b4642ca9d31810b8e1ee53cd0798a9e9ad81dfe6 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 7 Oct 2023 15:03:36 +0800 Subject: [PATCH] Use proper fallback value for Mark-of-the-Web URL References: https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/components/services/quarantine/quarantine_win.cc#211 https://hg.mozilla.org/mozilla-central/file/bd568ad893882d37f094d43cba3f62c78982cd05/toolkit/components/downloads/DownloadIntegration.sys.mjs#l537 --- src/base/utils/misc.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index c7ec9b8d5..e558ff745 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -622,6 +622,8 @@ QString Utils::Misc::zlibVersionString() #ifdef Q_OS_WIN bool Utils::Misc::applyMarkOfTheWeb(const Path &file, const QString &url) { + Q_ASSERT(url.isEmpty() || url.startsWith(u"http:") || url.startsWith(u"https:")); + const QString zoneIDStream = file.toString() + u":Zone.Identifier"; HANDLE handle = ::CreateFileW(zoneIDStream.toStdWString().c_str(), GENERIC_WRITE , (FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE) @@ -631,8 +633,9 @@ bool Utils::Misc::applyMarkOfTheWeb(const Path &file, const QString &url) // 5.6.1 Zone.Identifier Stream Name // https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/6e3f7352-d11c-4d76-8c39-2516a9df36e8 + const QString hostURL = !url.isEmpty() ? url : u"about:internet"_s; const QByteArray zoneID = QByteArrayLiteral("[ZoneTransfer]\r\nZoneId=3\r\n") - + (!url.isEmpty() ? u"HostUrl=%1\r\n"_s.arg(url).toUtf8() : QByteArray()); + + u"HostUrl=%1\r\n"_s.arg(hostURL).toUtf8(); DWORD written = 0; const BOOL writeResult = ::WriteFile(handle, zoneID.constData(), zoneID.size(), &written, nullptr);