Skip to content

Commit

Permalink
traversal: more robust error handling
Browse files Browse the repository at this point in the history
This fixes a bug in walkdir that happened on Windows when following
symlinks. It was triggered when opening a handle to the symlink failed.
In particular, this resulted in the two stacks in the walkdir iterator
getting out of sync. At some point, this tripped a panic when popping
from one stack would be fine but popping from the other failed because
it was empty.

We fix this by only pushing to both stacks if and only if both pushes
would succeed.

This bug was found via ripgrep. See:
BurntSushi/ripgrep#633 (comment)
  • Loading branch information
BurntSushi committed Feb 1, 2018
1 parent 3485764 commit e2b8983
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,15 @@ impl IntoIter {
});
list = DirList::Closed(entries.into_iter());
}
self.stack_list.push(list);
if self.opts.follow_links {
let ancestor = Ancestor::new(&dent).map_err(|err| {
Error::from_io(self.depth, err)
})?;
self.stack_path.push(ancestor);
}
// We push this after stack_path since creating the Ancestor can fail.
// If it fails, then we return the error and won't descend.
self.stack_list.push(list);
Ok(())
}

Expand Down

0 comments on commit e2b8983

Please sign in to comment.