Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Fix GlobalPalette serialized size

Open kennytv opened this issue 4 years ago • 4 comments

Within chunk packets, there is a new ByteBuf allocated with pre-calculated size based on the chunk section's non-air blocks and their block palettes. The global palette size returns 1 instead of 0 bytes and the buffer is needlessly extended - which doesn't cause any issues or warnings, since this is a special allocated buf inside of a packet, but still causes the mismatch in expected length and actual content (= being left with readableBytes > 0 despite all actual data having ended), annoying in custom protocol reading

kennytv avatar Sep 16 '21 18:09 kennytv

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 15 '21 23:11 stale[bot]

This issue has been automatically closed because it has not had activity in a long time. If the issue still applies to the most recent supported version, please open a new issue referencing this original issue.

stale[bot] avatar Nov 23 '21 01:11 stale[bot]

Related to this topic: There is another case where a wrong serialized size may occur.

public class PalettedContainer<T> implements PaletteResize<T> {
    ...

    public int getSerializedSize() {
        return 1 + this.palette.getSerializedSize() + FriendlyByteBuf.getVarIntSize(this.storage.getSize()) + this.storage.getRaw().length * 8;
    }

    ...
}

In this code FriendlyByteBuf.getVarIntSize(this.storage.getSize()) should actually be FriendlyByteBuf.getVarIntSize(this.storage.getRaw().length). I have opened a PR for this a long time ago here #872. However, a wrong conclusion has been made there in my opinion. It might be worth to reconsider this and adding it to this patch.

stonar96 avatar Nov 23 '21 10:11 stonar96

Yeah as mentioned by stonar, it might be nice to have a patch that both covers these size method issues.

Owen1212055 avatar Oct 22 '22 21:10 Owen1212055

Closing.

When discussing it internally it was brought up that it could technically cause issues if plugins do any stupid packet reading in this area. It's probably better to just bump this with mojang.

Owen1212055 avatar Dec 23 '22 18:12 Owen1212055

For reference, this has been fixed in 23w31a.

Owen1212055 avatar Aug 02 '23 21:08 Owen1212055