Fix a StackOverflowException reading windows runtime assemblies. #879
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-stack-overflow-due-to-winrt-projections"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
During
AssemblyReader.ReadCustomAttributesthere is a call toWindowsRuntimeProjections.ProjectWindowsRuntimeProjections.Projectwould callWindowsRuntimeProjections.HasAttribute, which would then calltype.CustomAttributes, which would end up back inAssemblyReader.ReadCustomAttributes. This would lead to a StackOverflowException.This wasn't an issue previously. My PR https://github.com/jbevain/cecil/pull/843 caused this sequence of calls to start resulting in a StackOverflowException.
Prior to my PR, there was a call to
metadata.RemoveCustomAttributeRange (owner);before the call toWindowsRuntimeProjections.Project. This meant that whenWindowsRuntimeProjections.HasAttributewould calltype.CustomAttributes, we'd still end up inAssemblyReader.ReadCustomAttributes, however, no attributes would be found because the following if would be true and lead to returning an empty collection.The old behavior was probably the wrong. Although I'm not certain what the tangible impact was.
The fix was pretty easy.
AssemblyReader.ReadCustomAttributeswill now pass in the custom attributes toWindowsRuntimeProjections.Projectavoiding the need to calltype.CustomAttributesincluding a test that verifies the change might be helpful
Fair point. I'll see if I can come up with something
I updated the PR with tests. A few comments on the tests
There was some logic to look in the 8.1 SDK. This is outdated and shouldn't exist anymore. I added logic to locate
Windows.winmdfrom the windows 10 SDK.In order for the StackOverflowException to be triggered,
Windows.winmdneeded to be read withApplyWindowsRuntimeProjections=true. It turns out none of the windows runtime tests were doing that today. I spoke with @TautvydasZilys about this and the conclusion was that it wouldn't be a bad thing if all of the windows runtime tests ran withApplyWindowsRuntimeProjectionsset tofalseand totrue. That is what the[TestCase(true)]and[TestCase(false)]changes are for.@jbevain please take a look.
@ -182,7 +182,7 @@ namespace Mono.Cecil.Tests {[Test]applyWindowsRuntimeProjections: false@ -17,19 +17,21 @@ namespace Mono.Cecil.Tests {protected abstract string [] ManagedClassTypeNames { get; }Style:
Hi @mrvoorhe,
Thanks for the PR. Please address the tidbits and this is good to go.
@ -17,19 +17,21 @@ namespace Mono.Cecil.Tests {protected abstract string [] ManagedClassTypeNames { get; }Fixed
@ -182,7 +182,7 @@ namespace Mono.Cecil.Tests {[Test]Fixed
@jbevain I addressed your comments. Thanks!
Thanks!