Extend depth-limit guard to deserialize_option, deserialize_newtype_struct, and newtype_variant_seed - #382
Open
scadastrangelove wants to merge 1 commit into
Conversation
…truct, and newtype_variant_seed depth_count! (added in 3Hren#277) only wrapped visit_seq/visit_map/the Ext-marker visit_newtype_struct. This extends it to the three remaining recursion-capable forwarding points in Deserializer/VariantAccess: - deserialize_option - deserialize_newtype_struct (both branches) - VariantAccess::newtype_variant_seed Each site needs an explicit &mut *self/&mut *de reborrow rather than passing self/de directly, since a generic D: Deserializer<'de> parameter does not get an implicit reborrow the way a concretely-typed &mut T parameter does. Adds fail_depth_limit_option, fail_depth_limit_newtype_struct, and fail_depth_limit_newtype_variant regression tests, mirroring the existing fail_depth_limit test. Discovered by the rust-in-peace security pipeline (https://github.com/scadastrangelove/rust-in-peace/).
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.
Closes #381.
depth_count!(added in #277) only wrappedvisit_seq/visit_map/theExt-markervisit_newtype_struct. This extends it to the three remaining recursion-capable forwardingpoints in
Deserializer/VariantAccess:deserialize_optiondeserialize_newtype_struct(both branches)VariantAccess::newtype_variant_seedEach site needs an explicit
&mut *self/&mut *dereborrow rather than passingself/dedirectly — the existing macro usages that pass a value into a concrete
&mut Deserializerparameter (e.g.
SeqAccess::new(self, len)) get an implicit reborrow, but a genericD: Deserializer<'de>parameter (asVisitor::visit_some/visit_newtype_structandDeserializeSeed::deserializeare) does not — without the explicit reborrow this doesn't compile(
E0382: use of moved value).Testing
fail_depth_limit_option,fail_depth_limit_newtype_struct,fail_depth_limit_newtype_varianttormp-serde/tests/decode.rs, mirroring the existingfail_depth_limittest. All three reproduce a stack overflow / wrong result on unpatchedmasterand pass cleanly (DepthLimitExceeded) with this patch.cargo test -p rmp-serde -p rmp— 390 tests across allsuites (lib/decode/encode/serde/round/doctests), 0 failed.
Discovered by the rust-in-peace security pipeline.