Skip to content

Stack overflow in PEAssembly::GetResource() #111537

@ArtemRazin

Description

@ArtemRazin

I have a tool that "hides" embedded resources within an assembly. The idea is to redirect embedded resources to another assembly, which is loaded within the handler of AppDomain.AssemblyResolve. In this process, the "resource assembly" is loaded from bytes. This approach has worked reliably for years, but recently, I've received several reports from customers about the tool crashing with a stack overflow error.

After extensive testing, I was finally able to reproduce the issue on my test machine running Windows 10 with the latest .NET 9.0 SDK.

While debugging the problem, I discovered something strange. When PEAssembly::GetResource() detects that a resource is located in another assembly, it resolves that assembly and calls PEAssembly::GetResource() again, passing the target assembly as the last parameter. However, instead of searching for the resource in the target assembly, it continues to search in the original assembly, ignoring the last parameter.

This behavior repeats endlessly, ultimately resulting in a stack overflow error.

It appears the issue was introduced in the following commit:
eae1542

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions