Browse Source

Fix #1340: infinite recursion in DelegateConstruction due to recursive local function being mistreated as delegate construction.

pull/1347/head
Siegfried Pammer 7 years ago
parent
commit
1854a33749
  1. 3
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 2
      ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs
  3. 3
      ICSharpCode.Decompiler/IL/Transforms/LocalFunctionDecompiler.cs

3
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -517,11 +517,14 @@ namespace ICSharpCode.Decompiler.CSharp @@ -517,11 +517,14 @@ namespace ICSharpCode.Decompiler.CSharp
var part = method;
var connectedMethods = new Queue<MethodDefinitionHandle>();
var processedMethods = new HashSet<MethodDefinitionHandle>();
var processedNestedTypes = new HashSet<TypeDefinitionHandle>();
connectedMethods.Enqueue(part);
while (connectedMethods.Count > 0) {
part = connectedMethods.Dequeue();
if (!processedMethods.Add(part))
continue;
try {
ReadCodeMappingInfo(module, declaringType, info, parent, part, connectedMethods, processedNestedTypes);
} catch (BadImageFormatException) {

2
ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs

@ -155,6 +155,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -155,6 +155,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var targetMethod = ((IInstructionWithMethodOperand)value.Arguments[1]).Method;
if (!IsAnonymousMethod(decompilationContext.CurrentTypeDefinition, targetMethod))
return null;
if (LocalFunctionDecompiler.IsLocalFunctionMethod(targetMethod.ParentModule.PEFile, (MethodDefinitionHandle)targetMethod.MetadataToken))
return null;
target = value.Arguments[0];
if (targetMethod.MetadataToken.IsNil)
return null;

3
ICSharpCode.Decompiler/IL/Transforms/LocalFunctionDecompiler.cs

@ -21,8 +21,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -21,8 +21,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{
var metadata = module.Metadata;
var method = metadata.GetMethodDefinition(methodHandle);
var declaringType = method.GetDeclaringType();
if ((method.Attributes & MethodAttributes.Assembly) == 0 || !method.IsCompilerGenerated(metadata))
if ((method.Attributes & MethodAttributes.Assembly) == 0 || !(method.IsCompilerGenerated(metadata) || declaringType.IsCompilerGenerated(metadata)))
return false;
if (!ParseLocalFunctionName(metadata.GetString(method.Name), out _, out _))

Loading…
Cancel
Save