-
Notifications
You must be signed in to change notification settings - Fork 221
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
Properly handle static interface methods as entrypoints #1275
Conversation
When a static Interface method is selected as an Entrypoint when analyzing an Android app, WALA creates an invokeinterface instead of an invokestatic instruction in FakeRootMethod. This will lead to an out-of-array read when resolving the receiver for an interface invocation. A test can be simply an Android app generated by Android Studio for a Basic Activity demo (either Java or Kotlin). In my case, the problem occurs for handling: 40149 = invokeinterface < Application, Landroidx/window/layout/WindowMetricsCalculator, getOrCreate()Landroidx/window/layout/WindowMetricsCalculator; > @32353 exception:40150 And the exception is as follows: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.lambda$getTargetsForCall$0(SSAPropagationCallGraphBuilder.java:2072) at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder$CrossProductRec.rec(SSAPropagationCallGraphBuilder.java:542) at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.iterateCrossProduct(SSAPropagationCallGraphBuilder.java:2055) at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.getTargetsForCall(SSAPropagationCallGraphBuilder.java:2079) at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder$ConstraintVisitor.visitInvokeInternal(SSAPropagationCallGraphBuilder.java:1159) at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder$ConstraintVisitor.visitInvoke(SSAPropagationCallGraphBuilder.java:1115) at com.ibm.wala.ssa.SSAInvokeInstruction.visit(SSAInvokeInstruction.java:94) at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.addBlockInstructionConstraints(SSAPropagationCallGraphBuilder.java:273) at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.addNodeInstructionConstraints(SSAPropagationCallGraphBuilder.java:250) at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.unconditionallyAddConstraintsFromNode(SSAPropagationCallGraphBuilder.java:226) at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.addConstraintsFromNode(SSAPropagationCallGraphBuilder.java:191) at com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder.addConstraintsFromNewNodes(PropagationCallGraphBuilder.java:308) at com.ibm.wala.ipa.callgraph.propagation.StandardSolver.solve(StandardSolver.java:53) at com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder.makeCallGraph(PropagationCallGraphBuilder.java:248) This commit prioritizes a static method over an interface method and addresses the above problem.
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 changes look good to me! And thanks for the contribution! But can we add a test case for this? I think it shouldn't be too hard, but if you need help let me know
I have included a test, with the Android app, the test code and the needed JAR files. The WALA jars are compiled from an earlier snapshot that has the mentioned issue. |
@hjjandy I meant that we should add a unit test. My feeling is this issue should occur with any static interface https://github.com/wala/WALA/tree/master/core/src/testSubjects/java You could add another small Java source file, and then create a JUnit test like this one: Your test would create the appropriate |
@hjjandy I went ahead and added a unit test so we can merge. Please see the code in case you'd like to contribute and add tests in the future. |
When a static Interface method is selected as an Entrypoint, WALA creates an invokeinterface instead of an invokestatic instruction in FakeRootMethod. This will lead to an out-of-array read when resolving the receiver for an interface invocation.
A test can be simply an Android app generated by Android Studio for a Basic Activity demo (either Java or Kotlin). In my case, the problem occurs for handling:
40149 = invokeinterface < Application, Landroidx/window/layout/WindowMetricsCalculator, getOrCreate()Landroidx/window/layout/WindowMetricsCalculator; > @32353 exception:40150
And the exception is as follows:
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.lambda$getTargetsForCall$0(SSAPropagationCallGraphBuilder.java:2072)
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder$CrossProductRec.rec(SSAPropagationCallGraphBuilder.java:542)
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.iterateCrossProduct(SSAPropagationCallGraphBuilder.java:2055)
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.getTargetsForCall(SSAPropagationCallGraphBuilder.java:2079)
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder$ConstraintVisitor.visitInvokeInternal(SSAPropagationCallGraphBuilder.java:1159)
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder$ConstraintVisitor.visitInvoke(SSAPropagationCallGraphBuilder.java:1115)
at com.ibm.wala.ssa.SSAInvokeInstruction.visit(SSAInvokeInstruction.java:94)
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.addBlockInstructionConstraints(SSAPropagationCallGraphBuilder.java:273)
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.addNodeInstructionConstraints(SSAPropagationCallGraphBuilder.java:250)
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.unconditionallyAddConstraintsFromNode(SSAPropagationCallGraphBuilder.java:226)
at com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder.addConstraintsFromNode(SSAPropagationCallGraphBuilder.java:191)
at com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder.addConstraintsFromNewNodes(PropagationCallGraphBuilder.java:308)
at com.ibm.wala.ipa.callgraph.propagation.StandardSolver.solve(StandardSolver.java:53)
at com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder.makeCallGraph(PropagationCallGraphBuilder.java:248)
This commit prioritizes a static method over an interface method and addresses the above problem.