@@ -494,7 +494,7 @@ fn round_variant_string() {
494494 }
495495 }
496496
497- do_test ! ( |b| Serializer :: new( b ) ) ;
497+ do_test ! ( Serializer :: new) ;
498498 do_test ! ( |b| Serializer :: new( b) . with_struct_map( ) ) ;
499499 do_test ! ( |b| Serializer :: new( b) . with_struct_tuple( ) ) ;
500500 do_test ! ( |b| Serializer :: new( b) . with_struct_map( ) ) ;
@@ -565,6 +565,50 @@ fn roundtrip_some() {
565565 assert_roundtrips ( Some ( "hi" . to_string ( ) ) ) ;
566566}
567567
568+ /// Some types don't fully consume their input SeqAccess, leading to incorrect
569+ /// deserializes.
570+ ///
571+ /// https://github.com/3Hren/msgpack-rust/issues/287
572+ #[ test]
573+ fn checked_seq_access_len ( )
574+ {
575+ #[ derive( Serialize ) ]
576+ struct Input {
577+ a : [ & ' static str ; 4 ] ,
578+ d : & ' static str ,
579+ }
580+
581+ #[ allow( dead_code) ]
582+ #[ derive( Deserialize , Debug ) ]
583+ struct Output {
584+ a : [ String ; 2 ] ,
585+ c : String ,
586+ }
587+
588+ let mut buffer = Vec :: new ( ) ;
589+ let mut serializer = Serializer :: new ( & mut buffer)
590+ . with_binary ( )
591+ . with_struct_map ( ) ;
592+
593+ // The bug is basically that Output will successfully deserialize from input
594+ // because the [String; 0] deserializer doesn't drain the SeqAccess, and
595+ // the two fields it leaves behind can then be deserialized into `v`
596+
597+ let data = Input {
598+ a : [ "b" , "b" , "c" , "c" ] ,
599+ d : "d" ,
600+ } ;
601+
602+ data. serialize ( & mut serializer) . expect ( "failed to serialize" ) ;
603+
604+ let mut deserializer = rmp_serde:: Deserializer :: new (
605+ Cursor :: new ( & buffer)
606+ ) . with_binary ( ) ;
607+
608+ Output :: deserialize ( & mut deserializer)
609+ . expect_err ( "Input round tripped into Output; this shouldn't happen" ) ;
610+ }
611+
568612#[ ignore]
569613#[ test]
570614fn roundtrip_some_failures ( ) {
0 commit comments