Skip to content
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

anewarray behaves wierdly #835

Closed
C0D3-M4513R opened this issue Jul 31, 2024 · 8 comments
Closed

anewarray behaves wierdly #835

C0D3-M4513R opened this issue Jul 31, 2024 · 8 comments

Comments

@C0D3-M4513R
Copy link

C0D3-M4513R commented Jul 31, 2024

Describe the bug

A clear and concise description of what the bug is.

anewarray doesn't handle invalid array types correctly on saving

To Reproduce

Steps to reproduce the behavior:

Add the following in a method:

iconst_3 
anewarray [Ljava/lang/Object;
pop 

Then save. There is no error, but afaik this is not allowed, since anewarray can only construct single dimensional arrays.

Close and open the bytecode again.

It now says:

iconst_3 
anewarray LLjava/lang/Object;
pop 

Now try:

iconst_3 
anewarray [[Ljava/lang/Object;
pop 

It apears to save correctly in the ui.

Try to open the bytecode again, only to see that no bytecode is there.
There are stacktraces.

Exception

Stacktraces

11:16:42.819 [AssemblerPane/ForkJoinPool.commonPool-worker-17] ERROR: Uncaught exception when assembling contents of Method: <init>()V
java.lang.IllegalStateException: Expected InstanceType
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:42)
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:25)
	at dev.xdark.blw.type.Types.arrayTypeFromDescriptor(Types.java:80)
	at dev.xdark.blw.type.Types.objectTypeFromInternalName(Types.java:68)
	at dev.xdark.blw.asm.internal.Util.wrapTypeInsn(Util.java:63)
	at dev.xdark.blw.asm.internal.AsmMethodVisitor.visitTypeInsn(AsmMethodVisitor.java:91)
	at org.objectweb.asm.ClassReader.readCode(ClassReader.java:2482)
	at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1512)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:745)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:425)
	at dev.xdark.blw.asm.internal.InternalAsmLibrary.read(InternalAsmLibrary.java:82)
	at dev.xdark.blw.asm.AsmBytecodeLibrary.read(AsmBytecodeLibrary.java:22)
	at me.darknet.assembler.compile.JvmCompiler.applyOverlay(JvmCompiler.java:41)
	at me.darknet.assembler.compile.JvmCompiler.compile(JvmCompiler.java:85)
	at software.coley.recaf.services.assembler.AbstractAssemblerPipeline.compile(AbstractAssemblerPipeline.java:120)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline.assemble(JvmAssemblerPipeline.java:73)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline$Proxy$_$$_WeldClientProxy.assemble(Unknown Source)
	at software.coley.recaf.ui.pane.editing.assembler.AssemblerPane.lambda$assemble$31(AssemblerPane.java:404)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1773)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1491)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2073)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
11:16:47.720 [JvmAssemblerPipeline/ForkJoinPool.commonPool-worker-17] ERROR: Uncaught error creating class printer for: com/mojang/math/Constants
java.lang.IllegalStateException: Expected InstanceType
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:42)
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:25)
	at dev.xdark.blw.type.Types.arrayTypeFromDescriptor(Types.java:80)
	at dev.xdark.blw.type.Types.objectTypeFromInternalName(Types.java:68)
	at dev.xdark.blw.asm.internal.Util.wrapTypeInsn(Util.java:63)
	at dev.xdark.blw.asm.internal.AsmMethodVisitor.visitTypeInsn(AsmMethodVisitor.java:91)
	at org.objectweb.asm.ClassReader.readCode(ClassReader.java:2482)
	at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1512)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:745)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:425)
	at dev.xdark.blw.asm.internal.InternalAsmLibrary.read(InternalAsmLibrary.java:82)
	at dev.xdark.blw.asm.AsmBytecodeLibrary.read(AsmBytecodeLibrary.java:22)
	at me.darknet.assembler.printer.JvmClassPrinter.<init>(JvmClassPrinter.java:34)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline.classPrinter(JvmAssemblerPipeline.java:161)
	at software.coley.recaf.services.assembler.AbstractAssemblerPipeline.memberPrinter(AbstractAssemblerPipeline.java:130)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline.disassemble(JvmAssemblerPipeline.java:85)
	at software.coley.recaf.services.assembler.AssemblerPipeline.disassemble(AssemblerPipeline.java:175)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline$Proxy$_$$_WeldClientProxy.disassemble(Unknown Source)
	at software.coley.recaf.ui.pane.editing.assembler.AssemblerPane.lambda$disassemble$13(AssemblerPane.java:317)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1491)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2073)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
11:16:52.869 [JvmAssemblerPipeline/ForkJoinPool.commonPool-worker-17] ERROR: Uncaught error creating class printer for: com/mojang/math/Constants
java.lang.IllegalStateException: Expected InstanceType
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:42)
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:25)
	at dev.xdark.blw.type.Types.arrayTypeFromDescriptor(Types.java:80)
	at dev.xdark.blw.type.Types.objectTypeFromInternalName(Types.java:68)
	at dev.xdark.blw.asm.internal.Util.wrapTypeInsn(Util.java:63)
	at dev.xdark.blw.asm.internal.AsmMethodVisitor.visitTypeInsn(AsmMethodVisitor.java:91)
	at org.objectweb.asm.ClassReader.readCode(ClassReader.java:2482)
	at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1512)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:745)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:425)
	at dev.xdark.blw.asm.internal.InternalAsmLibrary.read(InternalAsmLibrary.java:82)
	at dev.xdark.blw.asm.AsmBytecodeLibrary.read(AsmBytecodeLibrary.java:22)
	at me.darknet.assembler.printer.JvmClassPrinter.<init>(JvmClassPrinter.java:34)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline.classPrinter(JvmAssemblerPipeline.java:161)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline.disassemble(JvmAssemblerPipeline.java:79)
	at software.coley.recaf.services.assembler.AssemblerPipeline.disassemble(AssemblerPipeline.java:173)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline$Proxy$_$$_WeldClientProxy.disassemble(Unknown Source)
	at software.coley.recaf.ui.pane.editing.assembler.AssemblerPane.lambda$disassemble$13(AssemblerPane.java:317)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1491)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2073)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
11:16:58.667 [AssemblerPane/ForkJoinPool.commonPool-worker-18] ERROR: Uncaught exception when assembling contents of Method: <init>()V
java.lang.IllegalStateException: Expected InstanceType
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:42)
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:25)
	at dev.xdark.blw.type.Types.arrayTypeFromDescriptor(Types.java:80)
	at dev.xdark.blw.type.Types.objectTypeFromInternalName(Types.java:68)
	at dev.xdark.blw.asm.internal.Util.wrapTypeInsn(Util.java:63)
	at dev.xdark.blw.asm.internal.AsmMethodVisitor.visitTypeInsn(AsmMethodVisitor.java:91)
	at org.objectweb.asm.ClassReader.readCode(ClassReader.java:2482)
	at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1512)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:745)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:425)
	at dev.xdark.blw.asm.internal.InternalAsmLibrary.read(InternalAsmLibrary.java:82)
	at dev.xdark.blw.asm.AsmBytecodeLibrary.read(AsmBytecodeLibrary.java:22)
	at me.darknet.assembler.compile.JvmCompiler.applyOverlay(JvmCompiler.java:41)
	at me.darknet.assembler.compile.JvmCompiler.compile(JvmCompiler.java:85)
	at software.coley.recaf.services.assembler.AbstractAssemblerPipeline.compile(AbstractAssemblerPipeline.java:120)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline.assemble(JvmAssemblerPipeline.java:73)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline$Proxy$_$$_WeldClientProxy.assemble(Unknown Source)
	at software.coley.recaf.ui.pane.editing.assembler.AssemblerPane.lambda$assemble$31(AssemblerPane.java:404)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1773)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1491)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2073)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
11:16:59.038 [AssemblerPane/ForkJoinPool.commonPool-worker-18] ERROR: Uncaught exception when assembling contents of Method: <init>()V
java.lang.IllegalStateException: Expected InstanceType
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:42)
	at dev.xdark.blw.type.TypeReader.read(TypeReader.java:25)
	at dev.xdark.blw.type.Types.arrayTypeFromDescriptor(Types.java:80)
	at dev.xdark.blw.type.Types.objectTypeFromInternalName(Types.java:68)
	at dev.xdark.blw.asm.internal.Util.wrapTypeInsn(Util.java:63)
	at dev.xdark.blw.asm.internal.AsmMethodVisitor.visitTypeInsn(AsmMethodVisitor.java:91)
	at org.objectweb.asm.ClassReader.readCode(ClassReader.java:2482)
	at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1512)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:745)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:425)
	at dev.xdark.blw.asm.internal.InternalAsmLibrary.read(InternalAsmLibrary.java:82)
	at dev.xdark.blw.asm.AsmBytecodeLibrary.read(AsmBytecodeLibrary.java:22)
	at me.darknet.assembler.compile.JvmCompiler.applyOverlay(JvmCompiler.java:41)
	at me.darknet.assembler.compile.JvmCompiler.compile(JvmCompiler.java:85)
	at software.coley.recaf.services.assembler.AbstractAssemblerPipeline.compile(AbstractAssemblerPipeline.java:120)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline.assemble(JvmAssemblerPipeline.java:73)
	at software.coley.recaf.services.assembler.JvmAssemblerPipeline$Proxy$_$$_WeldClientProxy.assemble(Unknown Source)
	at software.coley.recaf.ui.pane.editing.assembler.AssemblerPane.lambda$assemble$31(AssemblerPane.java:404)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1773)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1491)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2073)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)

Screenshots

If applicable, add screenshots to help explain your problem.

I am on the commit 6b86401.

@jumanji144
Copy link
Collaborator

There is no verification check for the anewarray type, the correct syntax is anewarray Ltype/internal/name;.

We can add a verification error if that will resolve your issue

@Col-E Col-E added usage Not a bug, but a question/problem regarding usage 4.X labels Jul 31, 2024
@C0D3-M4513R
Copy link
Author

C0D3-M4513R commented Jul 31, 2024

@jumanji144 it is?
image
I see more issues then

I guess the second bit should be the following instead:

iconst_1 
multianewarray [[Ljava/lang/Object; 1
astore test1

@C0D3-M4513R C0D3-M4513R changed the title anewarray doesn't handle invalid array types correctly on saving anewarray behaves wierdly Jul 31, 2024
@jumanji144
Copy link
Collaborator

huh, that is weird. I have never seen this behavior occur.

I will adjust the code accordingly

Thanks for the report!

@jumanji144
Copy link
Collaborator

Fixed with 6aeec14

@C0D3-M4513R
Copy link
Author

I can still reproduce this on my fork of Recaf.
I just rebased my pr #805 to 6aeec14.
Differences: https://github.com/Pixel-gaming/Recaf/compare/6aeec14f84b1a17d5d9acd7a081ae9f7bf4a5a39..dev4-nix

@jumanji144
Copy link
Collaborator

jumanji144 commented Jul 31, 2024

I have tested the code you provided and it successfully compiles back and reads back the same.

I altered the behavior of anewarray to handle array descriptors now.

Please provide a sample where the behavior is not as desired.

@Col-E Col-E added bug and removed usage Not a bug, but a question/problem regarding usage labels Jul 31, 2024
@C0D3-M4513R
Copy link
Author

C0D3-M4513R commented Jul 31, 2024

I thought that anewarray isn't supposed to have array types in general.
I had the opcode usage confused. Sorry.
I can confirm, that the provided code does indeed compile and decompile correctly.

@jumanji144
Copy link
Collaborator

anewarray can have array descriptors but only if only 1 array size is given in the multi dimensional construction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants