Skip to content
This repository has been archived by the owner on Aug 17, 2024. It is now read-only.

Commit

Permalink
Add some fuzz tests and skip the lines with non utf-8 content
Browse files Browse the repository at this point in the history
  • Loading branch information
Peltoche committed Nov 29, 2023
1 parent 6e2913d commit 5477a57
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ jobs:
command: test
args: --all-features

fuzz:
name: Test Suite
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install cargo-fuzz
uses: taiki-e/install-action@v2
with:
tool: cargo-fuzz

- name: Nightly
run: rustup default nightly

- name: Run Fuzzer
run: cargo +nightly fuzz run ical -- -max_total_time=10

lints:
name: Lints
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
26 changes: 26 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "ical-fuzz"
version = "0.0.0"
publish = false

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.ical]
path = ".."

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[profile.release]
debug = 1

[[bin]]
name = "ical"
path = "fuzz_targets/ical.rs"
test = false
doc = false
12 changes: 12 additions & 0 deletions fuzz/fuzz_targets/ical.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![no_main]

extern crate libfuzzer_sys;
extern crate ical;


use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let c = std::io::Cursor::new(data);
for _ in ical::IcalParser::new(c) {}
});
4 changes: 2 additions & 2 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<B: BufRead> LineRead for LineReader<B> {
} else {
// This is the first iteration, next_start isn't been filled yet.
for line in self.reader.by_ref().lines() {
let line = line.unwrap();
let line = line.ok()?;
self.number += 1;

if !line.is_empty() {
Expand All @@ -130,7 +130,7 @@ impl<B: BufRead> LineRead for LineReader<B> {
}

for line in self.reader.by_ref().lines() {
let mut line = line.unwrap();
let mut line = line.ok()?;

if line.is_empty() {
self.number += 1;
Expand Down

0 comments on commit 5477a57

Please sign in to comment.