java.lang.OutOfMemoryError while saving a chunk (Array overflow)
The Bug
By using books of random text (https://www.youtube.com/watch?v=uw7vEGhKoH8) it is possible to prevent chunk saving.
This can however be taken to the extreme, by filling a chest with alternating books, copying the chest using control + middle click, then filling another chest with the chests of books.
doing this process once-twice more results in a single chest with large amounts of data in it.
This chest can be saved in the creative toolbar, allowing it to be done on multiple servers very quickly.
The next step is to place lots and lots of these chests all in 1 chunk (around 50-60).
That is all that is needed to crash the server. when the player leaves the chunk or the chunk attempts to save, the total size of the data is more than 2147483648 bytes.
2147483648 elements is the physical limit of an array in java, and since when saving it needs to turn into bytes. The stack limit is filled and the server crashes.
Attached is a crash log of the crash in a single player world.
One fix could be to put a try catch around the saving of nbt, however how this would solve sending the chunk over the internet when a client is connected to a server is unknown.
(i am unable to upload the chest with all the data, because it is too large)
Edit:
The process on a server would take much longer due to the networking code not being able to handle this large amount of data. on a server it is not possible to make a recursive chest without the client crashing due to packet size limitations.
However this does not make it impossible, it means that instead of having to place down 50 chests it is now 3883 individual chests (or shulker boxes).
Another note is that if a chest is filled with chests containing books (You can make them just not clone them into an item without client modifications to netcode) than any player attempting to open the chest will instantly crash. Furthurmore, if a player where to get this chest in there inventory, they would not be able to log in again. (This is a known thing to do on 2b2t)
(it is still possible to fill the chest with the chests containing the books, however you cannot open them again, else be instantly crashed)
This could mean that there are other areas where this could cause a server crash (such as in the compression library)
Another file attached is the hotbar.nbt (its where the saved hotbar stuff is)
it contains 2 books of random characters and a chest with the alternating book pattern
Crash report
Description: Exception in server tick loop java.lang.OutOfMemoryError: Requested array size exceeds VM limit at java.util.Arrays.copyOf(Arrays.java:3236) at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118) at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93) at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153) at java.util.zip.DeflaterOutputStream.deflate(DeflaterOutputStream.java:253) at java.util.zip.DeflaterOutputStream.write(DeflaterOutputStream.java:211) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126) at java.io.DataOutputStream.write(DataOutputStream.java:107) at java.io.DataOutputStream.writeUTF(DataOutputStream.java:401) at java.io.DataOutputStream.writeUTF(DataOutputStream.java:323) at it.a(SourceFile:33) at ik.a(SourceFile:44) at id.a(SourceFile:423) at id.a(SourceFile:63) at id.a(SourceFile:423) at id.a(SourceFile:63) at ik.a(SourceFile:44) at id.a(SourceFile:423) at id.a(SourceFile:63) at id.a(SourceFile:423) at id.a(SourceFile:63) at id.a(SourceFile:423) at id.a(SourceFile:63) at ik.a(SourceFile:44) at id.a(SourceFile:423) at id.a(SourceFile:63) at id.a(SourceFile:423) at id.a(SourceFile:63) at id.a(SourceFile:423) at id.a(SourceFile:63) at ik.a(SourceFile:44)