Skip to content

Commit 99b3636

Browse files
committed
Add fuzzers
1 parent e86a69b commit 99b3636

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

fuzz/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
target
3+
libfuzzer

fuzz/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
[package]
3+
name = "unicode-segmentation-fuzz"
4+
version = "0.0.1"
5+
authors = ["Automatically generated"]
6+
7+
[dependencies.unicode-segmentation]
8+
path = ".."
9+
10+
# Prevent this from interfering with workspaces
11+
[workspace]
12+
members = ["."]
13+
14+
[[bin]]
15+
name = "graphemes"
16+
path = "fuzzers/graphemes.rs"
17+
18+
[[bin]]
19+
name = "words"
20+
path = "fuzzers/words.rs"
21+
22+
[[bin]]
23+
name = "equality"
24+
path = "fuzzers/equality.rs"

fuzz/fuzzers/equality.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
3+
extern crate libfuzzer_sys;
4+
extern crate unicode_segmentation;
5+
use std::str;
6+
use unicode_segmentation::UnicodeSegmentation;
7+
#[export_name="rust_fuzzer_test_input"]
8+
pub extern fn go(data: &[u8]) {
9+
if let Ok(s) = str::from_utf8(data) {
10+
let result = UnicodeSegmentation::graphemes(s, true).flat_map(|s| s.chars()).collect::<String>();
11+
assert_eq!(s, result);
12+
let result = s.split_word_bounds().flat_map(|s| s.chars()).collect::<String>();
13+
assert_eq!(s, result);
14+
15+
}
16+
}

fuzz/fuzzers/graphemes.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![no_main]
2+
3+
4+
extern crate libfuzzer_sys;
5+
6+
7+
extern crate unicode_segmentation;
8+
9+
use unicode_segmentation::UnicodeSegmentation;
10+
use std::str;
11+
12+
13+
#[export_name="rust_fuzzer_test_input"]
14+
pub extern fn go(data: &[u8]) {
15+
if let Ok(s) = str::from_utf8(data) {
16+
let g = UnicodeSegmentation::graphemes(s, true).collect::<Vec<_>>();
17+
assert!(UnicodeSegmentation::graphemes(s, true).rev().eq(g.iter().rev().cloned()));
18+
}
19+
}

fuzz/fuzzers/words.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![no_main]
2+
3+
4+
extern crate libfuzzer_sys;
5+
6+
7+
extern crate unicode_segmentation;
8+
9+
use unicode_segmentation::UnicodeSegmentation;
10+
use std::str;
11+
12+
13+
#[export_name="rust_fuzzer_test_input"]
14+
pub extern fn go(data: &[u8]) {
15+
if let Ok(s) = str::from_utf8(data) {
16+
let g = s.split_word_bounds().collect::<Vec<_>>();
17+
assert!(s.split_word_bounds().rev().eq(g.iter().rev().cloned()));
18+
}
19+
}

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