minetest-mods/i3

bags crash the game when dropped

loosewheel opened this issue · 6 comments

If a bag contains items with a fair amount of metadata (such as books), they crash the game when dropped.

Do you have a backtrace?

It causes the 'string too long for serializeString' error. Which is an unhandled exception, so you don't get more info.

The problem is caused because the metadata size of an item with an inventory is the aggregate of all the metadata of the items in its inventory. Even though an item may ensure its metadata doesn't exceed the 64kb, multiples in an inventory can.

I think the only way to reliably ensure against this is to determine the metadata size of the bag item including an item when it is being added, and if it would exceed the threshold, reject it through the inventory handlers.

I tested it by placing several items that I knew had large metadata in a bag and dropped it, because I suspected that it would crash.

Ultimately it is likely the rare case when it happens, but its certainly possible. Especially if it is dropped by a mod component (not a player), the game will crash for no apparent reason and be difficult to debug.

I disagree with a workaround, it should be properly fixed in the engine.

You are using Minetest 5.4, right? Because it was supposedly fixed in minetest/minetest#11511 and it normally should not crash on 5.5+

I'm using 5.4.1. I did see that conversation. I don't know if they were discussing a fix or just a trap to stop the server dropping out. In 5.4.1 as singleplayer the game drops out of memory. The only thing in the debug.txt file is using the books to make sure they had the metadata, and the next line is the string too long error when I dropped the bag.

I don't think there is a reliable way to get the size metadata will serialize to, because its an internal process. I've been converting the metadata to a table, replacing any ItemStacks in inventories to their string form, and then passing it through minetest.serialize. This is only an estimate so I've been leaving a few kilobytes grace for margin of error. Thus far it seems to be working.

I think I found the cause of this bug. I managed to drop an item with 1Mb in the metadata without crashing. I opened an issue on minetest. Hopefully this will be fixed in the next release, so this should be redundant.