Skip to content

Commit 4cb3507

Browse files
committed
Fix removing file with ctr of the form "\u{3}000"
1 parent 918e8a6 commit 4cb3507

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

libafl/src/corpus/inmemory_ondisk.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,24 +473,25 @@ impl<I> InMemoryOnDiskCorpus<I> {
473473

474474
fn remove_testcase(&self, testcase: &Testcase<I>) -> Result<(), Error> {
475475
if let Some(filename) = testcase.filename() {
476-
let mut ctr = String::new();
476+
let mut ctr = 0;
477477
if self.locking {
478478
let lockfile_path = self.dir_path.join(format!(".{filename}"));
479479
let mut lockfile = OpenOptions::new()
480480
.write(true)
481481
.read(true)
482482
.open(&lockfile_path)?;
483483

484+
let mut ctr_bytes = [0; 4];
484485
lockfile.lock_exclusive()?;
485-
lockfile.read_to_string(&mut ctr)?;
486-
ctr = ctr.trim().to_string();
486+
lockfile.read(&mut ctr_bytes)?;
487+
ctr = u32::from_le_bytes(ctr_bytes);
487488

488-
if ctr == "1" {
489+
if ctr == 1 {
489490
FileExt::unlock(&lockfile)?;
490491
drop(fs::remove_file(lockfile_path));
491492
} else {
492493
lockfile.seek(SeekFrom::Start(0))?;
493-
lockfile.write_all(&(ctr.parse::<u32>()? - 1).to_le_bytes())?;
494+
lockfile.write_all(&(ctr - 1).to_le_bytes())?;
494495
return Ok(());
495496
}
496497
}

0 commit comments

Comments
 (0)