Skip to content
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

Fix a timeout in fuzzing #9475

Merged
merged 1 commit into from
Oct 16, 2024
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
20 changes: 20 additions & 0 deletions crates/fuzzing/src/oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ pub struct StoreLimits(Arc<LimitsState>);
struct LimitsState {
/// Remaining memory, in bytes, left to allocate
remaining_memory: AtomicUsize,
/// Remaining times memories/tables can be grown
remaining_growths: AtomicUsize,
/// Whether or not an allocation request has been denied
oom: AtomicBool,
}
Expand All @@ -81,12 +83,30 @@ impl StoreLimits {
// Limits tables/memories within a store to at most 1gb for now to
// exercise some larger address but not overflow various limits.
remaining_memory: AtomicUsize::new(1 << 30),
// Also limit the number of times a memory or table may be grown.
// Otherwise infinite growths can exhibit quadratic behavior. For
// example Wasmtime could be configured with dynamic memories and no
// guard regions to grow into, meaning each memory growth could be a
// `memcpy`. As more data is added over time growths get more and
// more expensive meaning that fuel may not be effective at limiting
// execution time.
remaining_growths: AtomicUsize::new(100),
oom: AtomicBool::new(false),
}))
}

fn alloc(&mut self, amt: usize) -> bool {
log::trace!("alloc {amt:#x} bytes");
if self
.0
.remaining_growths
.fetch_update(SeqCst, SeqCst, |remaining| remaining.checked_sub(1))
.is_err()
{
self.0.oom.store(true, SeqCst);
log::debug!("too many growths, rejecting allocation");
return false;
}
match self
.0
.remaining_memory
Expand Down