-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9e94fc
commit 3908def
Showing
4 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![no_main] | ||
use std::alloc::Layout; | ||
|
||
use acid_alloc_hater::BumpSubject; | ||
use alloc_hater::{AllocatorOp, ArbLayout}; | ||
use arbitrary::{Arbitrary, Unstructured}; | ||
use libfuzzer_sys::fuzz_target; | ||
|
||
const MAX_SIZE: usize = 64 * 1024; | ||
const MAX_ALIGN_SHIFT: u8 = 12; // 4096 bytes | ||
|
||
#[derive(Clone, Debug)] | ||
struct Args { | ||
layout: Layout, | ||
ops: Vec<AllocatorOp>, | ||
} | ||
|
||
impl Arbitrary<'_> for Args { | ||
fn arbitrary(un: &mut Unstructured) -> arbitrary::Result<Args> { | ||
let size = usize::arbitrary(un)? % MAX_SIZE; | ||
let align_shift = u8::arbitrary(un)? % MAX_ALIGN_SHIFT; | ||
let align = 1_usize << align_shift; | ||
let layout = Layout::from_size_align(size, align).unwrap(); | ||
let ops = Vec::arbitrary(un)?; | ||
|
||
Ok(Args { layout, ops }) | ||
} | ||
} | ||
|
||
fuzz_target!(|args: Args| { | ||
let Args { layout, ops } = args; | ||
|
||
let mut bump = match BumpSubject::new(layout) { | ||
Ok(s) => s, | ||
Err(_) => return, | ||
}; | ||
|
||
let mut eval = alloc_hater::Evaluator::new(bump); | ||
eval.evaluate(ops).unwrap(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters