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

date -f / is doing an infinite loop on Is a directory #4539

Closed
sylvestre opened this issue Mar 18, 2023 · 6 comments · Fixed by #4572
Closed

date -f / is doing an infinite loop on Is a directory #4539

sylvestre opened this issue Mar 18, 2023 · 6 comments · Fixed by #4572
Labels

Comments

@sylvestre
Copy link
Sponsor Contributor

sylvestre commented Mar 18, 2023

Found with the fuzzer introduced in #4389

target/debug/coreutils date -f /
runs forever.

strace shows

read(3, 0x561efbdd70e0, 8192)           = -1 EISDIR (Is a directory)
read(3, 0x561efbdd70e0, 8192)           = -1 EISDIR (Is a directory)
read(3, 0x561efbdd70e0, 8192)           = -1 EISDIR (Is a directory)

while date -f / on GNU returns immediately without any message (which might be a bug)

@shanmukhateja
Copy link
Contributor

@sylvestre I'd like to give this a try.

@tertsdiepraam
Copy link
Member

This seems to be due to the .lines() call and the next calls on it. It honestly feels like bug in the standard library (or at the very least a pitfall).

@tertsdiepraam
Copy link
Member

This issue is related: rust-lang/rust#64144 (but they seem reluctant to change the behaviour)

@shanmukhateja
Copy link
Contributor

Yes, I agree. It is definitely related to Files not returning when accessing a directory.

@tertsdiepraam
Copy link
Member

We should probably check our entire codebase for this, basically every time we call BufReader::lines() this issue could be present.

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Mar 22, 2023

Okay, I actually don't think this is a footgun anymore. The problem is actually on our side, because we explicitly ignore the errors, which obviously doesn't get us the right behaviour. This would fix it for instance:

             DateSource::File(ref path) => {
                 file = File::open(path).unwrap();
                 let lines = BufReader::new(file).lines();
-                let iter = lines.filter_map(Result::ok).map(parse_date);
+                let iter = lines.map_while(Result::ok).map(parse_date);
                 Box::new(iter)
             }
             DateSource::Now => {

@shanmukhateja feel free to incorporate this in your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants