-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IL verification with ILVerify in addition to PEVerify #37994
Conversation
387a56d
to
f60966d
Compare
// Main module is the first one | ||
var result = verifier.Verify(resolver.Resolve(_allModuleData[0].SimpleName)); | ||
if (result.Count() == 0) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the catch
block is unnecessary. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch
😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'd missed the fact that Verify()
can throw exceptions. In that case, consider having the try { } catch { }
wrap the Verify()
call only, and catch specific exceptions rather than all.
This reverts commit 7e0ec94.
string message = printVerificationResult(result); | ||
throw new Exception("IL Verify failed unexpectedly: \r\n" + message); | ||
} | ||
catch (Exception) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From previous discussion with Jared, we don't distinguish between the different failure modes of ILVerify. Either it succeeds or it fails. That's why I added a comment to the test:
' ILVerify null ref
' Tracked by https//github.com/dotnet/roslyn/issues/58652
return; | ||
} | ||
|
||
throw new Exception("IL Verify succeeded unexpectedly"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was indeed a bug here. Thanks. Fixed by reducing usage of exceptions for failure scenarios.
var resolver = new Resolver(_allModuleData); | ||
var verifier = new ILVerify.Verifier(resolver); | ||
|
||
var mscorlibModule = _allModuleData.Single(m => m.IsCorLib); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string name = module.SimpleName; | ||
if (_imagesByName.ContainsKey(name)) | ||
{ | ||
throw new Exception($"Multiple modules named '{name}' were found"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider constructing the Dictionary<,>
in the caller, without throwing an exception. #Resolved
@@ -228,6 +233,127 @@ public void VerifyTypeIL(string typeName, string expected) | |||
} | |||
} | |||
|
|||
private sealed class Resolver : ILVerify.ResolverBase | |||
{ | |||
private readonly Dictionary<string, ImmutableArray<byte>> _imagesByName = new Dictionary<string, ImmutableArray<byte>>(StringComparer.OrdinalIgnoreCase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Main module is the first one | ||
var mainModuleReader = resolver.Resolve(_allModuleData[0].SimpleName); | ||
|
||
var (succeeded, errorMessage) = verify(verifier, mscorlibModule.SimpleName, mainModuleReader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (result.Count() != 0) | ||
{ | ||
return (false, printVerificationResult(result)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving this outside the try { } catch { }
. #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Count()
must be inside.
Relates to #22872