microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
22.54k stars 1.39k forks source link

Access denied (0xc0000005) when running under Windows 10 version 17763 #4574

Open leberechtreinhold opened 1 week ago

leberechtreinhold commented 1 week ago

Brief description of your issue

When running winget --list with scope machine on a Windows 10x86 build 17763, it crashes.

The reason is because PopulateIndexFromMSIX (https://github.com/microsoft/winget-cli/blob/6c54251308f91125f8fc8044f70fac69459295fe/src/AppInstallerRepositoryCore/Microsoft/PredefinedInstalledSourceFactory.cpp#L61) calls FindProvisionedPackages. This however seems to return a null value which is not catch by the catch hresult and is therefore a nullptr.

Looking at documentation, it does seem the minimum build would be 19041, not 17763, as stated in docs.

Windows 10, version 2004 (introduced in 10.0.19041.0)

https://learn.microsoft.com/en-us/uwp/api/windows.management.deployment.packagemanager.findprovisionedpackages?view=winrt-22621

MGdF9HpWoF

void PopulateIndexFromMSIX(SQLiteIndex& index, Manifest::ScopeEnum scope, SQLiteIndex* cacheData = nullptr)
{  
    //....
    AICLI_LOG(Repo, Verbose, << "Examining MSIX entries for " << ScopeToString(scope));

    IIterable<Package> packages;
    PackageManager packageManager;
    if (scope == Manifest::ScopeEnum::Machine)
    {
        packages = packageManager.FindProvisionedPackages();
    }

// --------------
template <typename D> auto consume_Windows_Management_Deployment_IPackageManager9<D>::FindProvisionedPackages() const
{
    void* packageCollection{};
    check_hresult(WINRT_IMPL_SHIM(winrt::Windows::Management::Deployment::IPackageManager9)->FindProvisionedPackages(&packageCollection));
    return winrt::Windows::Foundation::Collections::IVector<winrt::Windows::ApplicationModel::Package>{ packageCollection, take_ownership_from_abi };
}

// -------------- 
int32_t __stdcall FindProvisionedPackages(void** packageCollection) noexcept final try
{
    clear_abi(packageCollection);
    typename D::abi_guard guard(this->shim());
    *packageCollection = detach_from<winrt::Windows::Foundation::Collections::IVector<winrt::Windows::ApplicationModel::Package>>(this->shim().FindProvisionedPackages());
    return 0;
}
catch (...) { return to_hresult(); }

Steps to reproduce

Run winget --list with scope machine

Expected behavior

Not crash, return the base products. Since that specific os didnt have MSStore, it should be empty.

Actual behavior

Crash

Environment

Compiled release-v1.7.11261

Machine:

![UEMi2ND62J](https://github.com/microsoft/winget-cli/assets/24320606/25a5fd83-cc93-42bf-8557-0d01a4d07b17)
github-actions[bot] commented 1 week ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

leberechtreinhold commented 1 week ago

^ That crash happens with the package itself being null, here's the FindProvisionedPackages call.