Skip to content

Conversation

@wwh1004
Copy link
Contributor

@wwh1004 wwh1004 commented Dec 30, 2021

Fix #427
In code:

static void Test<T>(Dictionary<T, T> dict) { string.Concat(dict); }

MethodSig of 'string.Concat' is 'string (IEnumerable<KeyPairValue<T, T>>)' and dnlib will repeat substitute one of 'T' in 'KeyPairValue<T, T>' with ''KeyPairValue<T, T>'' itself, so there is an infinite loop. I add a parameter to disable substituting when get hash code for 'GenericInstSig.GenericArguments'.

About deleted code:

if (SubstituteGenericParameters) {
	InitializeGenericArguments();
	genericArguments.PushTypeArgs(gia.GenericArguments);
	hash += GetHashCode(gia.GenericType);
	genericArguments.PopTypeArgs();
}

GenericType is always TypeDef or TypeRef so it makes no sense to substitute generic parameters.

@CreateAndInject
Copy link
Contributor

image
Nice, but can you ensure this?

@wtfsck
Copy link
Contributor

wtfsck commented Dec 30, 2021

Thanks for the PR, will check later when I have more time.

@wwh1004 wwh1004 marked this pull request as draft January 21, 2022 14:45
@wwh1004
Copy link
Contributor Author

wwh1004 commented Jan 21, 2022

Still contains some problems. WIP

@wwh1004 wwh1004 marked this pull request as ready for review January 22, 2022 09:54
@wwh1004
Copy link
Contributor Author

wwh1004 commented Jan 22, 2022

Currently it will not resolve 'T' which is already resolved. In reflection apis, ga is always closed instantiation. So we don't need to substitute an already resolved ga.

@wwh1004
Copy link
Contributor Author

wwh1004 commented Jan 22, 2022

In theory, these changes will not affect SigComparer's handling of signatures which can be fully represented by System.Reflection types, since System.Reflection types do not allow open instantiation. It should ensure that the original code behavior is not changed. Namely it just fixes this issue without side effects.

@wtfsck wtfsck merged commit 2fae02e into 0xd4d:master Jan 31, 2022
@wtfsck
Copy link
Contributor

wtfsck commented Jan 31, 2022

Merged now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite loop in SigComparer.GetHashCode

3 participants