Skip to content

Commit

Permalink
ensure alignedbuf in map fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
lulf committed Jan 8, 2024
1 parent da78f9c commit 6b470b4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions fuzz/fuzz_targets/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ fn fuzz(ops: Input) {
const FLASH_RANGE: Range<u32> = 0x000..0x1000;

let mut map = HashMap::new();
let mut buf = [0; 260]; // Max length of test item serialized, rounded up to align to flash word.
#[repr(align(4))]
struct AlignedBuf([u8; 260]);
let mut buf = AlignedBuf([0; 260]); // Max length of test item serialized, rounded up to align to flash word.

let mut rng = rand_pcg::Pcg32::seed_from_u64(ops.seed);

Expand All @@ -121,7 +123,7 @@ fn fuzz(ops: Input) {
match block_on(sequential_storage::map::store_item(
&mut flash,
FLASH_RANGE,
&mut buf,
&mut buf.0,
item.clone(),
)) {
Ok(_) => {
Expand All @@ -135,7 +137,7 @@ fn fuzz(ops: Input) {
match block_on(sequential_storage::map::fetch_item::<TestItem, _>(
&mut flash,
FLASH_RANGE,
&mut buf,
&mut buf.0,
item.key,
)) {
Ok(Some(check_item))
Expand Down Expand Up @@ -165,7 +167,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::map::try_repair::<TestItem, _>(
&mut flash,
FLASH_RANGE,
&mut buf,
&mut buf.0,
))
.unwrap();
corruption_repaired = true;
Expand All @@ -178,7 +180,7 @@ fn fuzz(ops: Input) {
match block_on(sequential_storage::map::fetch_item::<TestItem, _>(
&mut flash,
FLASH_RANGE,
&mut buf,
&mut buf.0,
key,
)) {
Ok(Some(fetch_result)) => {
Expand Down Expand Up @@ -211,7 +213,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::map::try_repair::<TestItem, _>(
&mut flash,
FLASH_RANGE,
&mut buf,
&mut buf.0,
))
.unwrap();
corruption_repaired = true;
Expand Down

0 comments on commit 6b470b4

Please sign in to comment.