Compiled mapper: throw on a value not in the mappings instead of writing it - #176
Open
u9g wants to merge 1 commit into
Open
Compiled mapper: throw on a value not in the mappings instead of writing it#176u9g wants to merge 1 commit into
u9g wants to merge 1 commit into
Conversation
…ing it The compiled write/sizeOf mapper fell through to the raw value when it wasn't in the mappings (`mappings[value] || value`), so an unmapped name reached the underlying numeric type, serialized as NaN -> 0, and went out on the wire as a bogus packet. A packet name that doesn't exist in the current protocol state serialized to a single 0x00 byte with no body — a real packet id the peer then fails to decode. The interpreted mapper already throws here; make the compiled one match. The `|| value` fallback also meant a value legitimately mapped to 0 only worked by accident (0 is falsy, so the name itself was passed to the numeric type and serialized as NaN -> 0).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The compiled write/sizeOf
mapperfalls through to the raw value when it isn't in the mappings (mappings[value] || value), so an unmapped name reaches the underlying numeric type and serializes asNaN→0. The interpreted mapper throws<value> is not in the mappings valueon the same input; this makes the compiled one match.Why it matters: in node-minecraft-protocol, writing a packet name that doesn't exist in the current protocol state (e.g. mineflayer's physics loop sending
positionwhile a Velocity server transfer has the client in the configuration state) serialized to a single0x00byte with no body. In the configuration state that's a real packet id (client_information), so the proxy fails to decode it and kicks with "An internal error occurred in your connection." With this change the write raises a serialization error instead of putting corrupt bytes on the wire.The
|| valuefallback also meant a value legitimately mapped to0only worked by accident:0is falsy, so the name was passed to the numeric type and happened to serialize asNaN→0. Covered by the new test.Read is left as is (it still returns the raw id for an unknown value), since consumers rely on receiving unknown packets rather than a parse error.
Heads-up for consumers: anything that was serializing a mapper from
undefined/an unmapped value and silently getting0now throws. Found two in the login path and fixed them ahead of this:particleStatusin the configuration-phasesettings)settings)