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 file sync timing and prevent crash on missing SyncFromDiskMetadata #2595

Merged
merged 3 commits into from
Oct 9, 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
21 changes: 10 additions & 11 deletions libafl/src/stages/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,22 @@ where
}
}

let max_time = match last {
None => None,
Some(last) => Some(last + self.interval),
};
let new_max_time = max_time.unwrap_or(current_time());
let new_max_time = current_time();

let mut new_files = vec![];
for dir in &self.sync_dirs {
log::debug!("Syncing from dir: {:?}", dir);
let new_dir_files = find_new_files_rec(dir, &max_time)?;
let new_dir_files = find_new_files_rec(dir, &last)?;
new_files.extend(new_dir_files);
}
*state.metadata_mut::<SyncFromDiskMetadata>().unwrap() = SyncFromDiskMetadata {
last_time: new_max_time,
left_to_sync: new_files,
};
let sync_from_disk_metadata = state.metadata_mut::<SyncFromDiskMetadata>().unwrap();

let sync_from_disk_metadata = state
.metadata_or_insert_with(|| SyncFromDiskMetadata::new(new_max_time, new_files.clone()));

// At the very first sync, last_time and file_to_sync are set twice
sync_from_disk_metadata.last_time = new_max_time;
sync_from_disk_metadata.left_to_sync = new_files;

// Iterate over the paths of files left to sync.
// By keeping track of these files, we ensure that no file is missed during synchronization,
// even in the event of a target restart.
Expand Down
Loading