fix(wit-bindgen-wrpc): clear out variant decoder internal state after use #257
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.
This commit fixes a bug which manifests itself when decoding a list of enums that may have separate internal decoder objects to use.
The issue is that storing the internal state inside the bindgen'd
Decoder
becomes a problem on the second (or subsequent) elements of a list of the given enum.Given a
vec![SomeEnum::X, SomeEnum::Y]
the saved "state" for the first becomes the first decoder (i.e. the decoder forSomeEnum::X
). When it comes time to parse the discriminant and bytes forY
the existence of thestate
causes a short circuit.As the (wrong) decoder will generally try to process some bytes, you lose bytes from the input and then bytes are left over at the next attempt to decode (and then an error occurs). How this manifests is obviously specific to the enum, (wrong) decoder, and involved variants, how they are decoded -- i.e. where the decoding will fail.
This only happens for generating bindings for variant types (i.e. Rust enums), which use the
PayloadDecoder
machinery to dynamically pick which payload decoder to use, depending on the discriminant read.