[SPIGOT-7212] Issue with negative NBT values when deserializing data Created: 22/Dec/22  Updated: 25/Dec/24  Resolved: 23/Dec/22

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: takatalvi Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Environment:

Latest Spigot server on Windows. Configs in default state, plugins only Multiverse and Multiverse-Inventories.


Attachments: Text File 2022-12-21-7.log    
Version: CraftBukkit version 3627-Spigot-d90018e-c810c3e (MC: 1.19.3) (Implementing API version 1.19.3-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

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!



 Comments   
Comment by takatalvi [ 26/Dec/22 ]

Thank you so much for the quick fix!

Generated at Fri Mar 28 03:51:01 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.