File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // This Source Code Form is subject to the terms of the Mozilla Public
2+ // License, v. 2.0. If a copy of the MPL was not distributed with this
3+ // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+ //
5+ // Copyright (c) DUSK NETWORK. All rights reserved.
6+
7+ use std:: io:: Cursor ;
8+
9+ use node_data:: Serializable ;
10+ use node_data:: message:: Message ;
11+ use rand:: rngs:: StdRng ;
12+ use rand:: { Rng , SeedableRng } ;
13+
14+ #[ test]
15+ #[ ignore = "fuzz-like deserialization; run manually" ]
16+ // Randomized deserialization should never panic, even on malformed input.
17+ fn fuzz_message_deserialization_does_not_panic ( ) {
18+ let mut rng = StdRng :: seed_from_u64 ( 4242 ) ;
19+
20+ for _ in 0 ..1000 {
21+ let len = rng. gen_range ( 0 ..512 ) ;
22+ let mut bytes = vec ! [ 0u8 ; len] ;
23+ rng. fill ( & mut bytes[ ..] ) ;
24+
25+ let result = std:: panic:: catch_unwind ( || {
26+ let mut cursor = Cursor :: new ( bytes) ;
27+ let _ = Message :: read ( & mut cursor) ;
28+ } ) ;
29+
30+ assert ! ( result. is_ok( ) , "deserialization panicked" ) ;
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments