mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
[GH-ISSUE #407] sort_by_inode violates Ord and does not guarantee a total ordering leading to panic
#177
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @d0nutptr on GitHub (Jun 27, 2024).
Original GitHub issue: https://github.com/bootandy/dust/issues/407
Hello!
I happened to run into an interesting edge-case while cleaning up a few projects. While running
dustin a folder containing both files and symlinks I encountered this odd panic.I debugged the issue and discovered the issue is caused by
sort_by_inodeindir_walker.rs. The problem is that the implementation provided does not guarantee a total ordering if both files and symlinks are present. For example:Assume the folder contains the following nodes with names and
inode_devices:There does not exist a total order as there exists no way to order these three files in a way where the following comparisons are satisfied:
I tried to make as small of a testcase as possible, but it was actually really hard to trigger the behavior. This is the smallest test I could create that exhibited the crash:
@bootandy commented on GitHub (Jun 28, 2024):
That's interesting. I'll look into this.
Just trying that test and set it to run in a loop, I haven't seen it fail yet. I'm using ubuntu, which OS did you use ? & Does it take several runs to fail ?
@d0nutptr commented on GitHub (Jun 28, 2024):
Hey! Yea it can take a few goes in practice to crash.
It is exceedingly rare to find a situation where this happens in practice.
I fuzzed millions of configurations of files to see if i could make a smaller poc to send and came up with nothing.
If you run the above provided test case, though, it should be 100% reproducible.
@d0nutptr commented on GitHub (Jun 28, 2024):
Oh, and yes I use ubuntu :)
@bootandy commented on GitHub (Jun 28, 2024):
I see how this could happen. So this is genuine. (I just can't yet reproduce it). Going to have to think about this.
We could catch the panic and sort by name if that happens.
@bootandy commented on GitHub (Jun 28, 2024):
This is helping me think about it: I codifed your description in the issue:
@bootandy commented on GitHub (Jun 28, 2024):
https://github.com/bootandy/dust/pull/408
does this look like it would fix it ?
@d0nutptr commented on GitHub (Jun 28, 2024):
I think it would!
I wrote a simple hardness to formally verify the Ord property so let me try this new implementation to see if it can find a violation.
@d0nutptr commented on GitHub (Jun 28, 2024):
I assume I wrote a relatively reasonable definition to check total order here, but it looks like it verified! 🚢 it