Skip to content

Commit 9b20974

Browse files
authored
Merge pull request #107 from arthurscchan/new-fuzzer
OSS-Fuzz: Add new fuzzer upstream
2 parents 9d5d794 + ac1c634 commit 9b20974

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

fuzz/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ path = "fuzz_targets/streaming.rs"
2323
test = false
2424
doc = false
2525

26+
[[bin]]
27+
name = "process"
28+
path = "fuzz_targets/process.rs"
29+
test = false
30+
doc = false
31+
2632
# Work around https://github.com/rust-lang/cargo/issues/8338
2733
[workspace]

fuzz/fuzz_targets/process.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
decompose_canonical(c, |_| {});
68+
}
69+
}
70+
9 => {
71+
// Fuzz decompose_compatible
72+
if let Some(c) = chars.next() {
73+
decompose_compatible(c, |_| {});
74+
}
75+
}
76+
_ => {}
77+
}
78+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy