8000 Fix string creating logic and add comments · unicode-rs/unicode-normalization@70f7d6a · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 70f7d6a

Browse files
committed
Fix string creating logic and add comments
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
1 parent 7b9eb47 commit 70f7d6a

File tree

1 file changed

+42
-44
lines changed

1 file changed

+42
-44
lines changed

fuzz/fuzz_targets/process.rs

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// The fuzzing harness fuzz test some of the the
2-
// unicode string normalization processing
1+
-// The fuzzing harness fuzz test some of the the
2+
-// unicode string normalization processing
33

44
#![no_main]
55

@@ -15,65 +15,63 @@ use unicode_normalization::{
1515
UnicodeNormalization,
1616
};
1717

18-
fuzz_target!(|data: &[u8]| {
19-
let mut data = data;
20-
let c = if let Some((char_value, remaining_data)) = data.split_first() {
21-
match std::char::from_u32(*char_value as u32) {
22-
Some(ch) => {
23-
data = remaining_data;
24-
ch
25-
}
26-
None => return,
27-
}
28-
} else {
29-
return;
30-
};
18+
fuzz_target!(|data: (u8, String)| {
19+
let (function_index, string_data) = data;
3120

32-
// Generate second character for fuzzing if data is enough
33-
let c2 = if let Some((char_value, remaining_data)) = data.split_first() {
34-
data = remaining_data;
35-
std::char::from_u32(*char_value as u32)
36-
} else {
37-
None
38-
};
39-
let string_data: String = data
40-
.iter()
41-
.filter_map(|&b| std::char::from_u32(b as u32))
42-
.collect();
21+
// Create an iterator for characters
22+
let mut chars = string_data.chars();
4323

44-
// Randomly choose a function target
45-
match data.first().map(|&b| b % 10) {
46-
Some(0) => {
47-
if let Some(c2) = c2 {
48-
let _ = compose(c, c2);
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);
4930
}
5031
}
51-
Some(1) => {
52-
let _ = canonical_combining_class(c);
32+
1 => {
33+
// Fuzz canonical_combining_class
34+
if let Some(c) = chars.next() {
35+
let _ = canonical_combining_class(c);
36+
}
5337
}
54-
Some(2) => {
55-
let _ = is_combining_mark(c);
38+
2 => {
39+
// Fuzz is_combining_mark
40+
if let Some(c) = chars.next() {
41+
let _ = is_combining_mark(c);
42+
}
5643
}
57-
Some(3) => {
44+
3 => {
45+
// Fuzz NFC
5846
let _ = string_data.nfc().collect::<String>();
5947
}
60-
Some(4) => {
48+
4 => {
49+
// Fuzz NFKD
6150
let _ = string_data.nfkd().collect::<String>();
6251
}
63-
Some(5) => {
52+
5 => {
53+
// Fuzz NFD
6454
let _ = string_data.nfd().collect::<String>();
6555
}
66-
Some(6) => {
56+
6 => {
57+
// Fuzz NFKC
6758
let _ = string_data.nfkc().collect::<String>();
6859
}
69-
Some(7) => {
60+
7 => {
61+
// Fuzz stream_safe
7062
let _ = string_data.stream_safe().collect::<String>();
7163
}
72-
Some(8) => {
73-
decompose_canonical(c, |_| {});
64+
8 => {
65+
// Fuzz decompose_canonical
66+
if let Some(c) = chars.next() {
67+
decompose_canonical(c, |_| {});
68+
}
7469
}
75-
Some(9) => {
76-
decompose_compatible(c, |_| {});
70+
9 => {
71+
// Fuzz decompose_compatible
72+
if let Some(c) = chars.next() {
73+
decompose_compatible(c, |_| {});
74+
}
7775
}
7876
_ => {}
7977
}

0 commit comments

Comments
 (0)
0