Copy INVOKEDYNAMIC args array to avoid leaking handle remaps, fixes #373

This commit is contained in:
Mumfrey committed 2019-12-13 14:21:39 +00:00
1 parent 8b9621a13b
commit 27ea2a9555
2 files changed
+19 -2

No files matched your search

@@ -37,6 +37,7 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Handle;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@@ -44,6 +45,7 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InnerClassNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Mixin;
@@ -90,6 +92,17 @@ class MixinInfo implements Comparable<MixinInfo>, IMixinInfo {
public MixinMethodNode(int access, String name, String desc, String signature, String[] exceptions) {
super(access, name, desc, signature, exceptions, MixinInfo.this);
}
@Override
public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
// Create a shallow copy of the bootstrap method args because the
// base implementation just passes the array by reference. This
// causes any changes applied to the cloned classnode to leak into
// the "master" ClassNode!
Object[] bsmArgs = new Object[bootstrapMethodArguments.length];
System.arraycopy(bootstrapMethodArguments, 0, bsmArgs, 0, bootstrapMethodArguments.length);
this.instructions.add(new InvokeDynamicInsnNode(name, descriptor, bootstrapMethodHandle, bsmArgs));
}
public boolean isInjector() {
return (this.getInjectorAnnotation() != null || this.isSurrogate());
@@ -429,10 +429,14 @@ public final class Bytecode {
out += String.format("[%s] %d", Bytecode.getOpcodeName(node), ((VarInsnNode)node).var);
} else if (node instanceof MethodInsnNode) {
MethodInsnNode mth = (MethodInsnNode)node;
out += String.format("[%s] %s %s %s", Bytecode.getOpcodeName(node), mth.owner, mth.name, mth.desc);
out += String.format("[%s] %s::%s%s", Bytecode.getOpcodeName(node), mth.owner, mth.name, mth.desc);
} else if (node instanceof FieldInsnNode) {
FieldInsnNode fld = (FieldInsnNode)node;
out += String.format("[%s] %s %s %s", Bytecode.getOpcodeName(node), fld.owner, fld.name, fld.desc);
out += String.format("[%s] %s::%s:%s", Bytecode.getOpcodeName(node), fld.owner, fld.name, fld.desc);
} else if (node instanceof InvokeDynamicInsnNode) {
InvokeDynamicInsnNode idc = (InvokeDynamicInsnNode)node;
out += String.format("[%s] %s%s { %s %s::%s%s }", Bytecode.getOpcodeName(node), idc.name, idc.desc,
Bytecode.getOpcodeName(idc.bsm.getTag(), "H_GETFIELD", 1), idc.bsm.getOwner(), idc.bsm.getName(), idc.bsm.getDesc());
} else if (node instanceof LineNumberNode) {
LineNumberNode ln = (LineNumberNode)node;
out += String.format("LINE=[%d] LABEL=[%s]", ln.line, ln.start.getLabel());