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
var part = method; var part = method;
var connectedMethods = new Queue<MethodDefinitionHandle>(); var connectedMethods = new Queue<MethodDefinitionHandle>();
var processedMethods = new HashSet<MethodDefinitionHandle>();
var processedNestedTypes = new HashSet<TypeDefinitionHandle>(); var processedNestedTypes = new HashSet<TypeDefinitionHandle>();
connectedMethods.Enqueue(part); connectedMethods.Enqueue(part);
while (connectedMethods.Count > 0) { while (connectedMethods.Count > 0) {
part = connectedMethods.Dequeue(); part = connectedMethods.Dequeue();
if (!processedMethods.Add(part))
continue;
try { try {
ReadCodeMappingInfo(module, declaringType, info, parent, part, connectedMethods, processedNestedTypes); ReadCodeMappingInfo(module, declaringType, info, parent, part, connectedMethods, processedNestedTypes);
} catch (BadImageFormatException) { } catch (BadImageFormatException) {

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

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

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

@ -21,8 +21,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{ {
var metadata = module.Metadata; var metadata = module.Metadata;
var method = metadata.GetMethodDefinition(methodHandle); 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; return false;
if (!ParseLocalFunctionName(metadata.GetString(method.Name), out _, out _)) if (!ParseLocalFunctionName(metadata.GetString(method.Name), out _, out _))

Loading…
Cancel
Save