Description
Brief description of your issue
When attempting to use PackageVersionInfo.GetMetadata, if there is a key that has a empty/null value the program using COM will terminate with a deference error. This is due to the lack of a null check inside of PackageVersionInfo::GetMetadata() inside of PackageVersionInfo.cpp in the Microsoft.Management.Deployment project.
Note: I fixed it by adding a check to see if the find could not find any value
My solution:
hstring PackageVersionInfo::GetMetadata(winrt::Microsoft::Management::Deployment::PackageVersionMetadataField const& metadataField)
{
::AppInstaller::Repository::PackageVersionMetadata metadataKey = GetRepositoryPackageVersionMetadata(metadataField);
::AppInstaller::Repository::IPackageVersion::Metadata metadata = m_packageVersion->GetMetadata();
auto result = metadata.find(metadataKey);
//Added: Had to add a check here to see if the result was empty
if (result == metadata.end())
{
return winrt::to_hstring("");
}
hstring resultString = winrt::to_hstring(result->second);
// The api uses "System" rather than "Machine" for install scope.
if (metadataField == PackageVersionMetadataField::InstalledScope && resultString == L"Machine")
{
return winrt::to_hstring(L"System");
}
return resultString;
}
Steps to reproduce
Use COM and call something like:
string silentUninstallString = match.CatalogPackage.InstalledVersion.GetMetadata(PackageVersionMetadataField.SilentUninstallCommand);
(Note: match is the MatchResult for searching for dbeaver.dbeaver)
Do a local package search and call this on something you have installed. I would recommend using dbeaver.dbeaver as it does not have a silent uninstall command in the registry and will cause the error.
Expected behavior
Should gracefully handle a particular key not having a value.
Actual behavior
Causes program to terminate ungracefully.
Environment
Windows Package Manager v1.10.340
Copyright (c) Microsoft Corporation. All rights reserved.
Windows: Windows.Desktop v10.0.26100.3476
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.25.340.0
Winget Directories
-----------------------------------------------------------------------------------------------------------------------
Logs %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\Diag…
User Settings %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\sett…
Portable Links Directory (User) %LOCALAPPDATA%\Microsoft\WinGet\Links
Portable Links Directory (Machine) C:\Program Files\WinGet\Links
Portable Package Root (User) %LOCALAPPDATA%\Microsoft\WinGet\Packages
Portable Package Root C:\Program Files\WinGet\Packages
Portable Package Root (x86) C:\Program Files (x86)\WinGet\Packages
Installer Downloads %USERPROFILE%\Downloads
Configuration Modules %LOCALAPPDATA%\Microsoft\WinGet\Configuration\Modules
Links
---------------------------------------------------------------------------
Privacy Statement https://aka.ms/winget-privacy
License Agreement https://aka.ms/winget-license
Third Party Notices https://aka.ms/winget-3rdPartyNotice
Homepage https://aka.ms/winget
Windows Store Terms https://www.microsoft.com/en-us/storedocs/terms-of-sale
Admin Setting State
--------------------------------------------------
LocalManifestFiles Disabled
BypassCertificatePinningForMicrosoftStore Disabled
InstallerHashOverride Disabled
LocalArchiveMalwareScanOverride Disabled
ProxyCommandLineOptions Disabled
DefaultProxy Disabled