From 23d7153fb1e62f441ee73da416fc0f7435451de0 Mon Sep 17 00:00:00 2001 From: John McPherson Date: Thu, 30 Apr 2020 10:12:56 -0700 Subject: [PATCH] Fix potential crash in public folder retrieval, and construct path ourself for now --- src/AppInstallerCommonCore/ExtensionCatalog.cpp | 5 ++++- src/AppInstallerCommonCore/Public/AppInstallerErrors.h | 1 + .../Microsoft/PreIndexedPackageSourceFactory.cpp | 8 ++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/AppInstallerCommonCore/ExtensionCatalog.cpp b/src/AppInstallerCommonCore/ExtensionCatalog.cpp index 7af522b918..291ea1fbe0 100644 --- a/src/AppInstallerCommonCore/ExtensionCatalog.cpp +++ b/src/AppInstallerCommonCore/ExtensionCatalog.cpp @@ -3,6 +3,7 @@ #pragma once #include "pch.h" #include "winget/ExtensionCatalog.h" +#include "AppInstallerErrors.h" #include "AppInstallerLogging.h" #include "AppInstallerStrings.h" @@ -19,7 +20,9 @@ namespace AppInstaller::Deployment std::filesystem::path Extension::GetPublicFolderPath() const { - return m_extension.GetPublicFolderAsync().get().Path().c_str(); + auto folder = m_extension.GetPublicFolderAsync().get(); + THROW_HR_IF(APPINSTALLER_CLI_ERROR_EXTENSION_PUBLIC_FAILED, !folder); + return folder.Path().c_str(); } winrt::Windows::ApplicationModel::PackageVersion Extension::GetPackageVersion() const diff --git a/src/AppInstallerCommonCore/Public/AppInstallerErrors.h b/src/AppInstallerCommonCore/Public/AppInstallerErrors.h index ba9cdd5ba9..07071f63c9 100644 --- a/src/AppInstallerCommonCore/Public/AppInstallerErrors.h +++ b/src/AppInstallerCommonCore/Public/AppInstallerErrors.h @@ -33,6 +33,7 @@ #define APPINSTALLER_CLI_ERROR_NO_SOURCES_DEFINED ((HRESULT)0x8A150015) #define APPINSTALLER_CLI_ERROR_MULTIPLE_APPLICATIONS_FOUND ((HRESULT)0x8A150016) #define APPINSTALLER_CLI_ERROR_NO_MANIFEST_FOUND ((HRESULT)0x8A150017) +#define APPINSTALLER_CLI_ERROR_EXTENSION_PUBLIC_FAILED ((HRESULT)0x8A150018) namespace AppInstaller { diff --git a/src/AppInstallerRepositoryCore/Microsoft/PreIndexedPackageSourceFactory.cpp b/src/AppInstallerRepositoryCore/Microsoft/PreIndexedPackageSourceFactory.cpp index dff3f37f71..663645a6f5 100644 --- a/src/AppInstallerRepositoryCore/Microsoft/PreIndexedPackageSourceFactory.cpp +++ b/src/AppInstallerRepositoryCore/Microsoft/PreIndexedPackageSourceFactory.cpp @@ -139,8 +139,12 @@ namespace AppInstaller::Repository::Microsoft THROW_HR(APPINSTALLER_CLI_ERROR_SOURCE_DATA_MISSING); } - std::filesystem::path indexLocation = extension->GetPublicFolderPath(); - indexLocation /= s_PreIndexedPackageSourceFactory_IndexFileName; + // To work around an issue with accessing the public folder, we are temporarily + // constructing the location ourself. This was already the case for the non-packaged + // runtime, and we can fix both in the future. The only problem with this is that + // the directory in the extension *must* be Public, rather than one set by the creator. + std::filesystem::path indexLocation = extension->GetPackagePath(); + indexLocation /= s_PreIndexedPackageSourceFactory_IndexFilePath; SQLiteIndex index = SQLiteIndex::Open(indexLocation.u8string(), SQLiteIndex::OpenDisposition::Immutable);