Skip to content

Commit f10caad

Browse files
committed
fix validateParameterIndex discarding parameters when the parent method has a bugged max_locals property
1 parent ed5ae3c commit f10caad

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

enigma/src/main/java/org/quiltmc/enigma/api/EnigmaProject.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,27 @@ public boolean isAnonymousOrLocal(ClassEntry classEntry) {
258258
* @param parameter the parameter to validate
259259
* @return whether the index is valid
260260
*/
261+
@SuppressWarnings("DataFlowIssue")
261262
public boolean validateParameterIndex(LocalVariableEntry parameter) {
262263
MethodEntry parent = parameter.getParent();
263264
EntryIndex index = this.jarIndex.getIndex(EntryIndex.class);
264265

265266
if (index.hasMethod(parent)) {
266267
AtomicInteger maxLocals = new AtomicInteger(-1);
267-
ClassEntry parentClass = parent != null ? parent.getParent() : null;
268+
ClassEntry parentClass = parent.getParent();
268269

269270
// find max_locals for method, representing the number of parameters it receives (JVMS§4.7.3)
270271
// note: parent class cannot be null, warning suppressed
271272
ClassNode classNode = this.getClassProvider().get(parentClass.getFullName());
272273
if (classNode != null) {
273274
classNode.methods.stream()
274275
.filter(node -> node.name.equals(parent.getName()) && node.desc.equals(parent.getDesc().toString()))
275-
.findFirst().ifPresent(node -> maxLocals.set(node.maxLocals));
276+
.findFirst().ifPresent(node -> {
277+
// occasionally it's possible to run into a method that has parameters, yet whose max locals is 0. java is stupid. we ignore those cases
278+
if (node.parameters.size() <= node.maxLocals) {
279+
maxLocals.set(node.maxLocals);
280+
}
281+
});
276282
}
277283

278284
// if maxLocals is -1 it's not found for the method and should be ignored

0 commit comments

Comments
 (0)