Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7212

Issue with negative NBT values when deserializing data

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • Latest Spigot server on Windows. Configs in default state, plugins only Multiverse and Multiverse-Inventories.

    • CraftBukkit version 3627-Spigot-d90018e-c810c3e (MC: 1.19.3) (Implementing API version 1.19.3-R0.1-SNAPSHOT)
    • Yes

      Hello,

      I've been running into an issue where Spigot throws a serialization exception due to NBT being saved with negative values. The exception originally came from Multiverse-Inventories, so I raised an issue with the developers of the plugin. They stated that serialization/deserialization is handled by Spigot and in order to fix this, it needs to be changed on Spigot's end.

      I cannot say how many other plugins are affected by this, but potentially any plugin which saves user inventories. The example in my case is a fireworks rocket with a negative value in Flight, specifically Flight:-2, which causes the rocket to explode instantly on use. This value is saved in a file by Multiverse-Inventories when there are separate inventories for different world groups. Saving is not an issue, but when this needs to be read (a player connects and the plugin loads their saved inventory):

       

      [09:38:07] [pool-5-thread-1/ERROR]: Could not call method 'public static org.bukkit.inventory.meta.ItemMeta org.bukkit.craftbukkit.v1_19_R2.inventory.CraftMetaItem$SerializableMeta.deserialize(java.util.Map) throws java.lang.Throwable' of class org.bukkit.craftbukkit.v1_19_R2.inventory.CraftMetaItem$SerializableMeta for deserialization
      java.lang.IllegalArgumentException: Power cannot be more than 127: 254
          at org.apache.commons.lang.Validate.isTrue(Validate.java:93) ~[commons-lang-2.6.jar:2.6]
          at org.bukkit.craftbukkit.v1_19_R2.inventory.CraftMetaFirework.setPower(CraftMetaFirework.java:398) ~[spigot-1.19.3-R0.1-SNAPSHOT.jar:3627-Spigot-d90018e-c810c3e]
          at org.bukkit.craftbukkit.v1_19_R2.inventory.CraftMetaFirework.<init>(CraftMetaFirework.java:184) ~[spigot-1.19.3-R0.1-SNAPSHOT.jar:3627-Spigot-d90018e-c810c3e]
          at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
          at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
          at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
          at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
          at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
          at org.bukkit.craftbukkit.v1_19_R2.inventory.CraftMetaItem$SerializableMeta.deserialize(CraftMetaItem.java:193) ~[spigot-1.19.3-R0.1-SNAPSHOT.jar:3627-Spigot-d90018e-c810c3e]
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
          at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
          at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
          at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeViaMethod(ConfigurationSerialization.java:85) ~[spigot-api-1.19.3-R0.1-SNAPSHOT.jar:?]
          at org.bukkit.configuration.serialization.ConfigurationSerialization.deserialize(ConfigurationSerialization.java:127) ~[spigot-api-1.19.3-R0.1-SNAPSHOT.jar:?]
          at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(ConfigurationSerialization.java:207) ~[spigot-api-1.19.3-R0.1-SNAPSHOT.jar:?]
          at com.onarandombox.multiverseinventories.utils.configuration.util.SerializationHelper.deserialize(SerializationHelper.java:125) ~[?:?]
          at com.onarandombox.multiverseinventories.utils.configuration.util.SerializationHelper.deserialize(SerializationHelper.java:116) ~[?:?]
          at com.onarandombox.multiverseinventories.utils.configuration.util.SerializationHelper.deserialize(SerializationHelper.java:116) ~[?:?]
          at com.onarandombox.multiverseinventories.utils.configuration.util.SerializationHelper.deserialize(SerializationHelper.java:116) ~[?:?]
          at com.onarandombox.multiverseinventories.utils.configuration.util.SerializationHelper.deserialize(SerializationHelper.java:116) ~[?:?]
          at com.onarandombox.multiverseinventories.utils.configuration.json.JsonConfiguration.convertMapsToSections(JsonConfiguration.java:75) ~[?:?]
          at com.onarandombox.multiverseinventories.utils.configuration.json.JsonConfiguration.loadFromString(JsonConfiguration.java:68) ~[?:?]
          at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:160) ~[spigot-api-1.19.3-R0.1-SNAPSHOT.jar:?]
          at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:128) ~[spigot-api-1.19.3-R0.1-SNAPSHOT.jar:?]
          at com.onarandombox.multiverseinventories.utils.configuration.json.JsonConfiguration.loadConfiguration(JsonConfiguration.java:110) ~[?:?]
          at com.onarandombox.multiverseinventories.utils.configuration.json.JsonConfiguration.loadConfiguration(JsonConfiguration.java:131) ~[?:?]
          at com.onarandombox.multiverseinventories.FlatFileProfileDataSource.getConfigHandleNow(FlatFileProfileDataSource.java:96) ~[?:?]
          at com.onarandombox.multiverseinventories.FlatFileProfileDataSource.access$100(FlatFileProfileDataSource.java:37) ~[?:?]
          at com.onarandombox.multiverseinventories.FlatFileProfileDataSource$ConfigLoader.call(FlatFileProfileDataSource.java:108) ~[?:?]
          at com.onarandombox.multiverseinventories.FlatFileProfileDataSource$ConfigLoader.call(FlatFileProfileDataSource.java:99) ~[?:?]
          at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
          at java.lang.Thread.run(Thread.java:833) ~[?:?]

      The MV developer gave me this description of the issue:

       

      The issue is that the NBT allows for any value between -128 and 127, which Spigot serializes as a value between 0 and 255. This is fine, but when deserializing, Spigot only accepts values from 0 to 127, which is what causes the error.

      I'd probably recommend changing the serialization to keep the sign bit, but I'm not sure if that's possible. Either way, the deserialization will need to be changed to accommodate the bigger range.

      I'm attaching a full server log, just in case.

      Thanks for reading!

            Unassigned Unassigned
            takatalvi takatalvi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: