8000 Handle multiple starters in the stream-safe fuzzer. by sunfishcode · Pull Request #77 · unicode-rs/unicode-normalization · GitHub
[go: up one dir, main page]

Skip to content

Handle multiple starters in the stream-safe fuzzer. #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions fuzz/fuzz_targets/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern crate libfuzzer_sys;
use std::str::Chars;
use std::cell::RefCell;
use std::rc::Rc;
use unicode_normalization::UnicodeNormalization;
use unicode_normalization::{char::canonical_combining_class, UnicodeNormalization};

const MAX_NONSTARTERS: u32 = 30;

Expand All @@ -30,8 +30,13 @@ impl<'a> Iterator for Counter<'a> {
type Item = char;

fn next(&mut self) -> Option<char> {
*self.value.borrow_mut() += 1;
self.iter.next()
let next = self.iter.next();
if let Some(c) = next {
if canonical_combining_class(c) != 0 {
*self.value.borrow_mut() += 1;
}
}
next
}
}

Expand All @@ -41,9 +46,8 @@ fuzz_target!(|input: String| {
let mut value = Rc::new(RefCell::new(0));
let counter = Counter { iter: stream_safe.chars(), value: Rc::clone(&mut value) };
for _ in counter.nfc() {
// Plus 2: one for the starter at the beginning of a sequence, and
// one for a starter that begins the following sequence.
assert!(*value.borrow() <= MAX_NONSTARTERS + 2);
// Plus 1: The iterator may consume a starter that begins the next sequence.
assert!(*value.borrow() <= MAX_NONSTARTERS + 1);
*value.borrow_mut() = 0;
}
});
0