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

Conversation

cube0x8
Copy link
Contributor

@cube0x8 cube0x8 commented Oct 8, 2024

I (think I) fixed the following two issues in the SyncFromDisk stage:

  1. The last_time used to determine when to sync files was being updated by adding a fixed interval to the previous check time. This caused newly created files to be re-synced multiple times until the sync interval caught up with their timestamp. Let's say we start the fuzzer at 10:00:00 and begin debugging. After the first sync, the last_time is updated to 10:00:05. Now, after 8 minutes of debugging, it’s 10:08:00, and we’re still debugging. During this time, we created two files (A and B) in the sync directory at 10:03:00. At the next sync iteration, the last_time is still 10:00:05, so the fuzzer syncs the files A and B. However, because the last_time is behind the actual creation time of the files (10:03:00), A and B continue to be re-synced repeatedly until the last_time catches up to their timestamps.

Solution: we better store the current_time() as last_time and check the files creation time against the previous last_time.

  1. To update the SyncFromDiskMetadata we were doing: state.metadata_mut::<SyncFromDiskMetadata>().unwrap(), which could cause a crash if the metadata was not present in state (first sync)

last_time: new_max_time,
left_to_sync: new_files,
};
match state.metadata_map_mut().get_mut::<SyncFromDiskMetadata>() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use state.metadata_or_insert_with here, should be shorter

@domenukk
Copy link
Member

domenukk commented Oct 9, 2024

Ah now we have one extra allocation :D
Well I guess that's ok here(?)

@domenukk
Copy link
Member

domenukk commented Oct 9, 2024

But actually, just set them to default values, you set them one step below anyway?

@cube0x8
Copy link
Contributor Author

cube0x8 commented Oct 9, 2024

can you define "default values"? UNIX_EPOCH for max_time and empty vector for left_to_sync?

@domenukk
Copy link
Member

domenukk commented Oct 9, 2024

just 0 and Vec::new()

@domenukk
Copy link
Member

domenukk commented Oct 9, 2024

We can even remove the parameters from new alltogether, it's not used anywhere else

@cube0x8
Copy link
Contributor Author

cube0x8 commented Oct 9, 2024

We can even remove the parameters from new alltogether, it's not used anywhere else

I'd proceed like this then

@domenukk domenukk merged commit 1e4d38d into AFLplusplus:main Oct 9, 2024
97 of 98 checks passed
riesentoaster pushed a commit to riesentoaster/LibAFL that referenced this pull request Dec 11, 2024
AFLplusplus#2595)

* max_time is the current_time(); SyncFromDiskMetadata might not be in state

* using metadata_or_insert_with
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants