ImageOnMap icon indicating copy to clipboard operation
ImageOnMap copied to clipboard

Paper 1.18.2 /tomap error "CraftItem failed"

Open ZerpCraft opened this issue 3 years ago • 55 comments

Plugin version is 4.2.2 Command run: /tomap https://i.imgur.com/hfn0QMe.png Other notes: After the error, the item frames turn invisible. Screenshot attached. Notice in the screenshot that on the right hand side the readout says I'm still looking at an Item_frame [entity.] 2022-03-05_09 12 49

Stack Trace:

fr.zcraft.imageonmap.quartzlib.tools.reflection.NMSException: Cannot set item stack tags
INFO at fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.addToItemStack(NBT.java:241) ~[ImageOnMap-4.2.2.jar:?]
INFO at fr.zcraft.imageonmap.quartzlib.tools.items.ItemStackBuilder.craftItem(ItemStackBuilder.java:264) ~[ImageOnMap-4.2.2.jar:?]
INFO at fr.moribus.imageonmap.ui.SplatterMapManager.lambda$placeSplatterMap$1(SplatterMapManager.java:311) ~[ImageOnMap-4.2.2.jar:?]
INFO at org.bukkit.craftbukkit.v1_18_R2.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.18.2.jar:git-Paper-224]
INFO at org.bukkit.craftbukkit.v1_18_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) ~[paper-1.18.2.jar:git-Paper-224]
INFO at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1521) ~[paper-1.18.2.jar:git-Paper-224]
INFO at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:483) ~[paper-1.18.2.jar:git-Paper-224]
INFO at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1444) ~[paper-1.18.2.jar:git-Paper-224]
INFO at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1218) ~[paper-1.18.2.jar:git-Paper-224]
INFO at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.18.2.jar:git-Paper-224]
INFO at java.lang.Thread.run(Thread.java:833) ~[?:?]
INFO Caused by: fr.zcraft.imageonmap.quartzlib.tools.reflection.NMSException: Unable to retrieve NBT data
INFO at fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.fromItemStack(NBT.java:77) ~[ImageOnMap-4.2.2.jar:?]
INFO at fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.addToItemStack(NBT.java:211) ~[ImageOnMap-4.2.2.jar:?]
INFO ... 10 more

ZerpCraft avatar Mar 05 '22 15:03 ZerpCraft

Update: I believe QuartzLib NBT.java is the problem. Line 309

try { Object tagCompound; try { //1.18 tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "t"); } catch (Exception e) { //1.17 try { tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "getTag"); } catch (Exception e2) { tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "a"); } }

        if (tagCompound == null) {
            tagCompound = Reflection.instantiate(MC_NBT_TAG_COMPOUND);
            Reflection.call(MC_ITEM_STACK, mcItemStack, "setTag", tagCompound);
        }
        return tagCompound;

    } catch (Exception exc) {
        //Older method
        try {
            Object tag = Reflection.getFieldValue(MC_ITEM_STACK, mcItemStack, "tag");

            if (tag == null) {
                tag = Reflection.instantiate(MC_NBT_TAG_COMPOUND);

                try {
                    Reflection.call(MC_ITEM_STACK, mcItemStack, "setTag", tag);
                } catch (NoSuchMethodException e) {
                    // If the set method change—more resilient,
                    // as the setTag will only update the field without any kind of callback.
                    Reflection.setFieldValue(MC_ITEM_STACK, mcItemStack, "tag", tag);
                }
            }

            return tag;
        } catch (Exception ex) {
            throw new NMSException("Unable to retrieve NBT tag from item", ex);
        }
    }

I believe this call is no longer working, but haven't figured out why yet. Comments suggest that his was added for 1.18, so maybe something has changed again? tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "t");

ZerpCraft avatar Mar 05 '22 17:03 ZerpCraft

Ok, that line was a bit of a red herring. Now I'm thinking it's this line: Reflection.call(MC_ITEM_STACK, mcItemStack, "setTag", tagCompound);

Throwing: [11:47:23 WARN]: java.lang.NoSuchMethodException: net.minecraft.world.item.ItemStack.setTag(net.minecraft.nbt.NBTTagCompound) [11:47:23 WARN]: at java.base/java.lang.Class.getDeclaredMethod(Class.java:2675) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.tools.reflection.Reflection.call(Reflection.java:317) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.getMcNBTCompound(NBT.java:324) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.fromItemStack(NBT.java:76) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.addToItemStack(NBT.java:215) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.tools.items.ItemStackBuilder.craftItem(ItemStackBuilder.java:264) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.moribus.imageonmap.ui.SplatterMapManager.lambda$placeSplatterMap$1(SplatterMapManager.java:313) [11:47:23 WARN]: at org.bukkit.craftbukkit.v1_18_R2.scheduler.CraftTask.run(CraftTask.java:101) [11:47:23 WARN]: at org.bukkit.craftbukkit.v1_18_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) [11:47:23 WARN]: at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1521) [11:47:23 WARN]: at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:483) [11:47:23 WARN]: at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1444) [11:47:23 WARN]: at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1218) [11:47:23 WARN]: at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) [11:47:23 WARN]: at java.base/java.lang.Thread.run(Thread.java:833) [11:47:23 WARN]: fr.zcraft.imageonmap.quartzlib.tools.reflection.NMSException: Unable to retrieve NBT data [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.fromItemStack(NBT.java:78) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.addToItemStack(NBT.java:215) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.tools.items.ItemStackBuilder.craftItem(ItemStackBuilder.java:264) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.moribus.imageonmap.ui.SplatterMapManager.lambda$placeSplatterMap$1(SplatterMapManager.java:313) [11:47:23 WARN]: at org.bukkit.craftbukkit.v1_18_R2.scheduler.CraftTask.run(CraftTask.java:101) [11:47:23 WARN]: at org.bukkit.craftbukkit.v1_18_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) [11:47:23 WARN]: at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1521) [11:47:23 WARN]: at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:483) [11:47:23 WARN]: at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1444) [11:47:23 WARN]: at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1218) [11:47:23 WARN]: at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) [11:47:23 WARN]: at java.base/java.lang.Thread.run(Thread.java:833) [11:47:23 WARN]: Caused by: fr.zcraft.imageonmap.quartzlib.tools.reflection.NMSException: Unable to retrieve NBT tag from item [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.getMcNBTCompound(NBT.java:348) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.fromItemStack(NBT.java:76) [11:47:23 WARN]: ... 11 more [11:47:23 WARN]: Caused by: java.lang.NoSuchFieldException: tag [11:47:23 WARN]: at java.base/java.lang.Class.getDeclaredField(Class.java:2610) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.tools.reflection.Reflection.getField(Reflection.java:170) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.tools.reflection.Reflection.getFieldValue(Reflection.java:137) [11:47:23 WARN]: at ImageOnMap-4.2.2.jar//fr.zcraft.imageonmap.quartzlib.components.nbt.NBT.getMcNBTCompound(NBT.java:332) [11:47:23 WARN]: ... 12 more [11:47:23 WARN]: [ImageOnMap] CraftItem failed

ZerpCraft avatar Mar 05 '22 17:03 ZerpCraft

Who knew I'd be learning so much today! So it seems the Reflections class is what's used to reference internal Minecraft classes? And on new version releases the class might be disappear or be changed to something else? So I need to find what the new class is I think.

ZerpCraft avatar Mar 05 '22 18:03 ZerpCraft

Yeah I think that's the problem indeed. Minecraft is changing internal classes names used to handle NBT data. We need either to find the new classes, or find a better way to handle the need to identify imageonmap maps without altering NBT data.

AmauryCarrade avatar Mar 05 '22 19:03 AmauryCarrade

Some effort in QuartzLib were started by @Vlammar, but are not done yet due to… our indisponibilities.

AmauryCarrade avatar Mar 05 '22 19:03 AmauryCarrade

Fixed it. tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "t"); The "t" needs to change to a "u" for 1.18.2

ZerpCraft avatar Mar 05 '22 20:03 ZerpCraft

cc @Vlammar

AmauryCarrade avatar Mar 06 '22 15:03 AmauryCarrade

The "t" needs to change to a "u" for 1.18.2

that's really a pain that they change for every version those damn method name

Vlammar avatar Mar 06 '22 19:03 Vlammar

sooo is the plugin gonna be updated? having this same issue on my server

CobaltBlue07 avatar Mar 10 '22 15:03 CobaltBlue07

Feel free to contribute if you want to speed things up. I don't have free time to work on IoM these days, sorry.

AmauryCarrade avatar Mar 12 '22 00:03 AmauryCarrade

Fixed it. tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "t"); The "t" needs to change to a "u" for 1.18.2

I can confirm. I downloaded the source to both ImageOnMap and Quartzlib, changed that one character from "t" to "u", recompiled and installed the Quartzlib package locally and then re-built ImageOnMap and it works fine now.

The old frames were left invisible where I put them originally and I had to break them to lay out a new grid. A decent temporary fix. Great plugin by the way, hope everyone is well.

Also, the version number is mislabeled in the pom file for the master branch. Everything says 0.0.6 except the pom, which is still saying 0.0.5

J-eremy avatar Mar 12 '22 12:03 J-eremy

Fixed it. tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "t"); The "t" needs to change to a "u" for 1.18.2

I can confirm. I downloaded the source to both ImageOnMap and Quartzlib, changed that one character from "t" to "u", recompiled and installed the Quartzlib package locally and then re-built ImageOnMap and it works fine now.

The old frames were left invisible where I put them originally and I had to break them to lay out a new grid. A decent temporary fix. Great plugin by the way, hope everyone is well.

Also, the version number is mislabeled in the pom file for the master branch. Everything says 0.0.6 except the pom, which is still saying 0.0.5

Any tutorial on how to do this?

ZeroBelowZero avatar Mar 12 '22 19:03 ZeroBelowZero

Fixed it. tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "t"); The "t" needs to change to a "u" for 1.18.2

I can confirm. I downloaded the source to both ImageOnMap and Quartzlib, changed that one character from "t" to "u", recompiled and installed the Quartzlib package locally and then re-built ImageOnMap and it works fine now. The old frames were left invisible where I put them originally and I had to break them to lay out a new grid. A decent temporary fix. Great plugin by the way, hope everyone is well. Also, the version number is mislabeled in the pom file for the master branch. Everything says 0.0.6 except the pom, which is still saying 0.0.5

Any tutorial on how to do this?

I would really wait for an official fix if I were you unless you already have an environment set up to build and compile the source. The fix is easy, but setting up the environment to compile and repackage is out of the scope of this thread.

The issue in compatibility is actually in Quartzlib, the library that that is included and built along side of the plugin, inside the jar not any of the code in the plugin itself if that makes any sense. The issue is, while it fixes it for 1.18.2, it breaks it for 1.18.1 etc etc.

Ill attach the jar I built, but you probably shouldn't be all willy nilly using any jar you stumble across on the internet. As there is plenty of room for malicious intent. If the developers don't want this file here feel free to delete it.

LINK REMOVED DUE TO SUSPICION OF INFECTED JAR The second there is an official update, make sure to use the official release, as I'm sure other stuff will be changed

J-eremy avatar Mar 12 '22 21:03 J-eremy

Fixed it. tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "t"); The "t" needs to change to a "u" for 1.18.2

I can confirm. I downloaded the source to both ImageOnMap and Quartzlib, changed that one character from "t" to "u", recompiled and installed the Quartzlib package locally and then re-built ImageOnMap and it works fine now. The old frames were left invisible where I put them originally and I had to break them to lay out a new grid. A decent temporary fix. Great plugin by the way, hope everyone is well. Also, the version number is mislabeled in the pom file for the master branch. Everything says 0.0.6 except the pom, which is still saying 0.0.5

Any tutorial on how to do this?

I would really wait for an official fix if I were you unless you already have an environment set up to build and compile the source. The fix is easy, but setting up the environment to compile and repackage is out of the scope of this thread.

The issue in compatibility is actually in Quartzlib, the library that that is included and built along side of the plugin, inside the jar not any of the code in the plugin itself if that makes any sense. The issue is, while it fixes it for 1.18.2, it breaks it for 1.18.1 etc etc.

Ill attach the jar I built, but you probably shouldn't be all willy nilly using any jar you stumble across on the internet. As there is plenty of room for malicious intent. If the developers don't want this file here feel free to delete it.

LINK REMOVED DUE TO SUSPICION OF INFECTED JAR The second there is an official update, make sure to use the official release, as I'm sure other stuff will be changed

Awesome! Thanks so much.

ZeroBelowZero avatar Mar 16 '22 22:03 ZeroBelowZero

@J-eremy according to my server provider after installing that fixed jar all my plugin jars got infected and i had to remove and reinstall all of them

CobaltBlue07 avatar Mar 18 '22 14:03 CobaltBlue07

@J-eremy according to my server provider after installing that fixed jar all my plugin jars got infected and i had to remove and reinstall all of them

Its definitely not from my jar. I literally only changed that one character in the lib. You might want to look at all your other jars before you go any further.

J-eremy avatar Mar 18 '22 15:03 J-eremy

I used your jar and it works completely fine for me, (thank you so much =)) didn't get any infected files or anything, though I did get quite a lot of temp files in my plugins folder, like, a lot... and I don't remember it being the case with the original version. image Not sure if it's something you can fix, though it's not very important, just a bit annoying that I have to clear it all up everytime 😅

Tanguygab avatar Mar 18 '22 16:03 Tanguygab

@J-eremy according to my server provider after installing that fixed jar all my plugin jars got infected and i had to remove and reinstall all of them

Its definitely not from my jar. I literally only changed that one character in the lib. You might want to look at all your other jars before you go any further.

this is what i thought so thats why i said according to my server provider... i think they are trying to money-grab things in order for me to pay more sadly.. last year they told me that my ram wasnt enough and my server was running out of performance (5gb ram for a 3 person server lmao) i just wanted to assure myself by saying it to you thank you again

CobaltBlue07 avatar Mar 18 '22 16:03 CobaltBlue07

I used your jar and it works completely fine for me, (thank you so much =)) didn't get any infected files or anything, though I did get quite a lot of temp files in my plugins folder, like, a lot... and I don't remember it being the case with the original version. image Not sure if it's something you can fix, though it's not very important, just a bit annoying that I have to clear it all up everytime 😅

That's weird I don't have any if that in my folder. you did extract the zip file so its the actual .jar in the plugins folder right? firefox_DC7x0JehVI github made me zip it. I did just re-download what I uploaded and the hashes are the same, feel free to download a hashing tool to make sure we are both using the same file.

@J-eremy according to my server provider after installing that fixed jar all my plugin jars got infected and i had to remove and reinstall all of them

Its definitely not from my jar. I literally only changed that one character in the lib. You might want to look at all your other jars before you go any further.

this is what i thought so thats why i said according to my server provider... i think they are trying to money-grab things in order for me to pay more sadly.. last year they told me that my ram wasnt enough and my server was running out of performance (5gb ram for a 3 person server lmao) i just wanted to assure myself by saying it to you thank you again

Yea that's not good. Sounds like a company I wouldn't want to work with. 5gb of ram is damn good for a small server, unless you are running every plugin known to man. Im also not sure if its even possible to have one jar effect other jars on the server, I could be wrong but i always assumed it could just mess up your whole world or give randoms access to what they shouldnt. If someone knows if a jar has write access to that folder after being loaded into memory please fill me in, because I am in no way a java programmer lol. @ZerpCraft is the real MVP here, I just applied his findings.

J-eremy avatar Mar 18 '22 16:03 J-eremy

github made me zip it. I did just re-download what I uploaded and the hashes are the same, feel free to download a hashing tool to make sure we are both using the same file.

no idea, I tried the jar you sent and yeah I do have the ImageOnMap.jar file in my plugins folder, it's just that everytime the plugin loads, it creates those temp files, not sure what I did wrong x)

Tanguygab avatar Mar 18 '22 20:03 Tanguygab

github made me zip it. I did just re-download what I uploaded and the hashes are the same, feel free to download a hashing tool to make sure we are both using the same file.

no idea, I tried the jar you sent and yeah I do have the ImageOnMap.jar file in my plugins folder, it's just that everytime the plugin loads, it creates those temp files, not sure what I did wrong x)

The only thing I seemed to find when I searched for that filename is something about fabric. Are you using a mod-loader like fabric or forge or are you using it with just the standard plugin stuff. I'm using paperMC as the server jar and letting it load plugins the normal way, no forge or fabric or any of that funny business. Try just spinning up a vanilla flavor of bukkit and see if those files are generated. I have personally never seen the plugin folder fill up like that. https://papermc.io/ thats the server Im using.

J-eremy avatar Mar 18 '22 22:03 J-eremy

paper as well, tried the latest dev build earlier

Tanguygab avatar Mar 18 '22 23:03 Tanguygab

@J-eremy The jar is indeed infected. Decompiling it shows the javassist package.

This is why you ALWAYS wait for official fixes. Problem is, this ended on the Bukkit.org page. Users should be informed.

Those who run it will need to clear the server folder from any jar file.

Now, if someone can understand what it did other than spreading itself, that'd be nice...

image_2022-03-29_16-34-18

FrecciaTricolore avatar Mar 29 '22 14:03 FrecciaTricolore

oh wow... i guess it wasnt my server provider trying to money grab me good thing i removed the jar after this happened and never reinstalled

CobaltBlue07 avatar Mar 29 '22 14:03 CobaltBlue07

I removed the links just to be sure. (I kept it on my side.)

If you want to contribute, instead of sharing links like this, open pull requests! Code will be visible to everyone and thinks like this are very unlikely to happen.

AmauryCarrade avatar Mar 29 '22 15:03 AmauryCarrade

@J-eremy The jar is indeed infected. Decompiling it shows the javassist package.

This is why you ALWAYS wait for official fixes. Problem is, this ended on the Bukkit.org page. Users should be informed.

Those who run it will need to clear the server folder from any jar file.

Now, if someone can understand what it did other than spreading itself, that'd be nice...

image_2022-03-29_16-34-18

What you are showing is not de-compiling it is just opening the jar as an archive. I compiled the jar the normal way with maven. Nothing was changed in the source for this plugin as the issue is with the library it uses not the code for the plugin itself and when I modified it I also did a PR for that repo.

I'm not a java programmer by far, I just know how to recompile things after small changes, as far as I can tell javassist is a library that must have been needed to compile the software and find no information on the internet saying its malicious in any way. Someone more knowledgeable than me please chime in.

If you go look at the PR's for Quartzlib you will see my pull request for what I changed.

All I can really say is what I already said, if your paranoid don't use it, wait until it is officially released. If you do use it make sure that your file has the same hash as the one I uploaded. But again, I don't see any signs of my file being infected in any way, nor do I appreciate being accused of distributing a malicious file. But on the other hand if it is actually found to be a problem then someone should really inspect upstream because I just cloned the git repositories and that would mean the problem is bigger than just this situation.

J-eremy avatar Mar 29 '22 17:03 J-eremy

There is an issue, I just re-compiled from upstream with a fresh pull the character fix and there is no javassist folder being generated in the jar. I don't know exactly whats going on. I'm going to leave this up to the people that actually know what they are doing as I can tinker but am not a programmer. Two mvn packages run the same way shouldn't output different artifacts.

J-eremy avatar Mar 29 '22 18:03 J-eremy

@J-eremy look at your jars, in the picture you sent, each of your plugins weighs double what it should. CMI 5,448 KB, Luckperms 3,123 KB. It' impossible. They are all infected. 159047018-526c9aec-e228-4503-ba36-167e7e479d3a

FrecciaTricolore avatar Mar 29 '22 19:03 FrecciaTricolore

AuthMe weighs 7 MB, your 14 MB Immagine 2022-03-29 211748

FrecciaTricolore avatar Mar 29 '22 19:03 FrecciaTricolore

As for javassist being "just a library", yeah, a library that generates bytecode on the fly and rewrites classes ... which sounds perfect if you want to craft an exploit payload.

synrg avatar Mar 29 '22 19:03 synrg