/src/unicode-normalization/fuzz/fuzz_targets/process.rs
Line | Count | Source |
1 | | // The fuzzing harness fuzz test some of the the |
2 | | // unicode string normalization processing |
3 | | |
4 | | #![no_main] |
5 | | |
6 | | #[macro_use] |
7 | | extern crate libfuzzer_sys; |
8 | | extern crate unicode_normalization; |
9 | | |
10 | | use unicode_normalization::{ |
11 | | char::{ |
12 | | canonical_combining_class, compose, decompose_canonical, decompose_compatible, |
13 | | is_combining_mark, |
14 | | }, |
15 | | UnicodeNormalization, |
16 | | }; |
17 | | |
18 | | fuzz_target!(|data: (u8, String)| { |
19 | | let (function_index, string_data) = data; |
20 | | |
21 | | // Create an iterator for characters |
22 | | let mut chars = string_data.chars(); |
23 | | |
24 | | // Randomly fuzz a target function |
25 | | match function_index % 10 { |
26 | | 0 => { |
27 | | // Fuzz compose with two distinct characters |
28 | | if let (Some(c1), Some(c2)) = (chars.next(), chars.next()) { |
29 | | let _ = compose(c1, c2); |
30 | | } |
31 | | } |
32 | | 1 => { |
33 | | // Fuzz canonical_combining_class |
34 | | if let Some(c) = chars.next() { |
35 | | let _ = canonical_combining_class(c); |
36 | | } |
37 | | } |
38 | | 2 => { |
39 | | // Fuzz is_combining_mark |
40 | | if let Some(c) = chars.next() { |
41 | | let _ = is_combining_mark(c); |
42 | | } |
43 | | } |
44 | | 3 => { |
45 | | // Fuzz NFC |
46 | | let _ = string_data.nfc().collect::<String>(); |
47 | | } |
48 | | 4 => { |
49 | | // Fuzz NFKD |
50 | | let _ = string_data.nfkd().collect::<String>(); |
51 | | } |
52 | | 5 => { |
53 | | // Fuzz NFD |
54 | | let _ = string_data.nfd().collect::<String>(); |
55 | | } |
56 | | 6 => { |
57 | | // Fuzz NFKC |
58 | | let _ = string_data.nfkc().collect::<String>(); |
59 | | } |
60 | | 7 => { |
61 | | // Fuzz stream_safe |
62 | | let _ = string_data.stream_safe().collect::<String>(); |
63 | | } |
64 | | 8 => { |
65 | | // Fuzz decompose_canonical |
66 | | if let Some(c) = chars.next() { |
67 | 104 | decompose_canonical(c, |_| {}); |
68 | | } |
69 | | } |
70 | | 9 => { |
71 | | // Fuzz decompose_compatible |
72 | | if let Some(c) = chars.next() { |
73 | 106 | decompose_compatible(c, |_| {}); |
74 | | } |
75 | | } |
76 | | _ => {} |
77 | | } |
78 | | }); |