Skip to content

Conversation

wwh1004
Copy link
Contributor

@wwh1004 wwh1004 commented Dec 28, 2021

No description provided.

@wtfsck
Copy link
Contributor

wtfsck commented Dec 29, 2021

That check was added due to: #331

Have you tested your code with the code from that issue?

@wtfsck
Copy link
Contributor

wtfsck commented Dec 29, 2021

Seems like the only problem is that it doesn't find the generic parameter in the type/method so it can't print the GP name, only its GP index. It shouldn't be a problem.

@wwh1004
Copy link
Contributor Author

wwh1004 commented Dec 29, 2021

The TypeSpec I printed is in instruction read by MethodBodyReader, which is read with gpContext.
https://github.com/0xd4d/dnlib/blob/master/src/Utils/SimpleLazyList.cs#L84
When I resolve TypeSpec without gpContext, 'elem.ContainsGenericParameter' will return false and result will be cached in 'elements[index]'. After that no matter what gpContext I pass to resolve TypeSpec, it will return the cached item but not construct a new one by reading with gpContext.

@wwh1004
Copy link
Contributor Author

wwh1004 commented Dec 29, 2021

That check was added due to: #331

Have you tested your code with the code from that issue?

I patched dnSpy's dnlib with this fix and load 'HelloWorld.MaliciousTypeSpecLoop.exe', dnSpy doesn't hang.

updated:
And also test with code:

var m = ModuleDefMD.Load("HelloWorld.MaliciousTypeSpecLoop.exe");
var t = m.ResolveTypeSpec(1).TypeSig;

I think this problem is fixed in ReadTypeDefOrRef(bool allowTypeSpec)
8ea0a56#diff-be44183bc77af09329bfdcdfc484ee0670c3c1b9eff0ef828c2974ede3b409c6R671
I don't know why there is a '!gpContext.IsEmpty'. It seems useless.

@wtfsck wtfsck merged commit 5b700d9 into 0xd4d:master Dec 29, 2021
@wtfsck
Copy link
Contributor

wtfsck commented Dec 29, 2021

Thanks for testing it! Merged.

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.

2 participants