File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,13 @@ test = false
4242doc = false
4343bench = false
4444
45+ [[bin ]]
46+ name = " test_fuzz_planar"
47+ path = " fuzz_targets/test_fuzz_planar.rs"
48+ test = false
49+ doc = false
50+ bench = false
51+
4552[[bin ]]
4653name = " test_fuzz_contraction"
4754path = " fuzz_targets/test_fuzz_contraction.rs"
Original file line number Diff line number Diff line change 1+ #![ no_main]
2+
3+ use arbitrary:: { Arbitrary , Unstructured } ;
4+ use libfuzzer_sys:: fuzz_target;
5+ use rustworkx_core:: petgraph:: graph:: UnGraph ;
6+ use rustworkx_core:: planar:: is_planar;
7+
8+ #[ derive( Debug , Arbitrary ) ]
9+ struct FuzzGraph {
10+ edges : Vec < ( usize , usize ) > ,
11+ node_count : usize ,
12+ }
13+
14+ fuzz_target ! ( |data: & [ u8 ] | {
15+ if let Ok ( fuzz_input) = FuzzGraph :: arbitrary( & mut Unstructured :: new( data) ) {
16+ fuzz_check_is_planar( & fuzz_input) ;
17+ }
18+ } ) ;
19+
20+ fn fuzz_check_is_planar ( input : & FuzzGraph ) {
21+ if input. node_count == 0 || input. edges . is_empty ( ) || input. node_count > 1000 {
22+ return ;
23+ }
24+
25+ let mut graph = UnGraph :: < ( ) , ( ) > :: default ( ) ;
26+ let mut nodes = Vec :: with_capacity ( input. node_count ) ;
27+
28+ for _ in 0 ..input. node_count {
29+ nodes. push ( graph. add_node ( ( ) ) ) ;
30+ }
31+
32+ for & ( u, v) in & input. edges {
33+ if u < input. node_count && v < input. node_count {
34+ graph. add_edge ( nodes[ u] , nodes[ v] , ( ) ) ;
35+ }
36+ }
37+
38+ let _ = is_planar ( & graph) ;
39+ }
You can’t perform that action at this time.
0 commit comments