Skip to content

Add check for fields not existing when writing container - #162

Closed
u9g wants to merge 2 commits into
ProtoDef-io:masterfrom
u9g:patch-1
Closed

Add check for fields not existing when writing container#162
u9g wants to merge 2 commits into
ProtoDef-io:masterfrom
u9g:patch-1

Conversation

@u9g

@u9g u9g commented Nov 12, 2024

Copy link
Copy Markdown
Contributor

There is a common problem that when the protocol gets updated some fields are silently writing garbage, so let's try to catch that.

Compiled container writes throw Missing field 'x' when a field is undefined and its type is one of protodef's value types: the numeric types, varint, bool, pstring, cstring, buffer, bitfield, mapper, array, count, container, or an alias of one. Bitfield members are always required.

Fields typed void, switch, option, or a type protodef does not define are not checked: those can encode an absent value (a switch whose default is void, prismarine-nbt's optional tags), and minecraft-protocol sends them undefined on purpose (use_entity with mouse: 0, a Slot without NBT on 1.13-1.20.4).

The interpreter is unchanged: it does not keep the JSON of a named type, so it cannot tell a switch alias from a varint alias.

minecraft-protocol's packetTest seeds SpawnInfo without seaLevel (1.21.2+); that varint was written as 0 before and now fails the login/respawn cases with Missing field 'seaLevel'.

@extremeheat

Copy link
Copy Markdown
Contributor

Interpreter should probably be updated also

A field typed void, switch, option, or a type protodef does not define may
legitimately be undefined; only the builtin value types are checked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants