dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.91k stars 4.63k forks source link

MethodDef validation seems miss to validate the last arg in `validateTokenSig` #96831

Open JJLovesLife opened 8 months ago

JJLovesLife commented 8 months ago

I was reading the CLR source code these days to learn better of dotnet. The following code seems to be a bug to me. https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/src/coreclr/utilcode/util.cpp#L1894-L1905 According to the ECMA spec:

GenParamCount is the number of generic parameters for the method.

So the ulArgCount here should be the # of parameters. And ulArgIx = 0 is the RetType, so [1, ulArgCount] will be the actual args. That means the condition in the if statement should be ulArgIx <= ulArgCount instead of <.

I did some debugging by debugger, it did forget to validate the last arg. If it is necessary, I might create an invalid dll that will not be detected by this piece of code.

steveisok commented 4 months ago

/cc @kg