Skip to content

Extend depth-limit guard to deserialize_option, deserialize_newtype_struct, and newtype_variant_seed - #382

Open
scadastrangelove wants to merge 1 commit into
3Hren:masterfrom
scadastrangelove:fix/depth-limit-guard-gaps
Open

Extend depth-limit guard to deserialize_option, deserialize_newtype_struct, and newtype_variant_seed#382
scadastrangelove wants to merge 1 commit into
3Hren:masterfrom
scadastrangelove:fix/depth-limit-guard-gaps

Conversation

@scadastrangelove

Copy link
Copy Markdown

Closes #381.

depth_count! (added in #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 — the existing macro usages that pass a value into a concrete &mut Deserializer
parameter (e.g. SeqAccess::new(self, len)) get an implicit reborrow, but a generic
D: Deserializer<'de> parameter (as Visitor::visit_some/visit_newtype_struct and
DeserializeSeed::deserialize are) does not — without the explicit reborrow this doesn't compile
(E0382: use of moved value).

Testing

  • Added fail_depth_limit_option, fail_depth_limit_newtype_struct,
    fail_depth_limit_newtype_variant to rmp-serde/tests/decode.rs, mirroring the existing
    fail_depth_limit test. All three reproduce a stack overflow / wrong result on unpatched
    master and pass cleanly (DepthLimitExceeded) with this patch.
  • Full existing suite green: cargo test -p rmp-serde -p rmp — 390 tests across all
    suites (lib/decode/encode/serde/round/doctests), 0 failed.

Discovered by the rust-in-peace security pipeline.

…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/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant