Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Aug 29, 2022

Fixes #1031

There apparently exists a Java obfuscator that attempts to break tools by setting the base class of a class to itself. This breaks us with a StackOverflowException:

public class c5<BaseHandler> extends c5<BaseHandler> { ... }
Stack overflow: IP: 0x11ae88918, fault addr: 0x30d984fd8
Stacktrace:
      at Java.Interop.Tools.JavaTypeSystem.Models.JavaClassModel.PrepareGenericInheritanceMapping () [0x00038] in <9ad2a4b0fd014215b74d06fce5575b7a>:0
      <...>
      at Java.Interop.Tools.JavaTypeSystem.Models.JavaClassModel.get_GenericInheritanceMapping () [0x00000] in <9ad2a4b0fd014215b74d06fce5575b7a>:0
      at Java.Interop.Tools.JavaTypeSystem.Models.JavaMethodModel/<>c__DisplayClass47_0.<FindBaseMethod>b__0 (Java.Interop.Tools.JavaTypeSystem.Models.JavaMethodModel) [0x00018] in <9ad2a4b0fd014215b74d06fce5575b7a>:0
      at System.Linq.Enumerable.TryGetFirst<TSource_REF> (System.Collections.Generic.IEnumerable`1<TSource_REF>,System.Func`2<TSource_REF, bool>,bool&) [0x0003f] in <80f7dc36b4e24f4b86610a67568d2e19>:0
      at System.Linq.Enumerable.FirstOrDefault<TSource_REF> (System.Collections.Generic.IEnumerable`1<TSource_REF>,System.Func`2<TSource_REF, bool>) [0x00000] in <80f7dc36b4e24f4b86610a67568d2e19>:0
      at Java.Interop.Tools.JavaTypeSystem.Models.JavaMethodModel.FindBaseMethod (Java.Interop.Tools.JavaTypeSystem.Models.JavaClassModel) [0x00028] in <9ad2a4b0fd014215b74d06fce5575b7a>:0
      at Java.Interop.Tools.JavaTypeSystem.Models.JavaClassModel.ResolveBaseMembers () [0x0002d] in <9ad2a4b0fd014215b74d06fce5575b7a>:0
      at Java.Interop.Tools.JavaTypeSystem.Models.JavaTypeCollection.ResolveCollection (Java.Interop.Tools.JavaTypeSystem.TypeResolutionOptions) [0x001d1] in <9ad2a4b0fd014215b74d06fce5575b7a>:0
      at generator.JavaTypeResolutionFixups.Fixup (string,string,Java.Interop.Tools.Cecil.DirectoryAssemblyResolver,string[]) [0x00055] in <a593e50c39a04879937ed01eece67aa3>:0
      at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions,Java.Interop.Tools.Cecil.DirectoryAssemblyResolver) [0x00230] in <a593e50c39a04879937ed01eece67aa3>:0
      at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions) [0x0001b] in <a593e50c39a04879937ed01eece67aa3>:0
      at Xamarin.Android.Binder.CodeGenerator.Main (string[]) [0x0000e] in <a593e50c39a04879937ed01eece67aa3>:0
      at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) [0x0002a] in <a593e50c39a04879937ed01eece67aa3>:0

We can add a check for this scenario to prevent the StackOverflowException and instead remove the offending type. This removal will be logged with other removals in the java-resolution-report.log:

The class '[Class] my.namespace.c5' was removed because the base type 'my.namespace.c5' is invalid.

@jpobst jpobst marked this pull request as ready for review August 29, 2022 20:43
@jonpryor jonpryor merged commit 58de60f into main Aug 30, 2022
@jonpryor jonpryor deleted the invalid-base-type branch August 30, 2022 14:45
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StackOverflow when binding library containing class with base type set to itself

3 participants