rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.64k stars 12.74k forks source link

Readdir iterator fails for vxworks since version 1.70 to 1.78 #127756

Closed biabbas closed 2 months ago

biabbas commented 4 months ago

Here is the program that reproduces this:

use std::path::Path;
use std::fs;
use std::io;
fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
    println!("Read directory");
    let dirs = fs::read_dir(path)?;
    println!("Directory read {:?}",dirs);
    for child in dirs {
        println!("child {:?}",child);
        let child = child?;
        if child.file_type()?.is_dir() {
            remove_dir_all_recursive(&child.path())?;
        } else {
            fs::remove_file(&child.path())?;
        }
    }   
    fs::remove_dir(path)
}
fn main(){
    let args: Vec<String> = std::env::args().collect();
    let directory=&args[1];
    println!("Hello, world - will remove {}",directory);
    let path = Path::new(directory);
    let result = remove_dir_all_recursive(path);
    println!("Result {:?} ",result);
}

Output: image

The test directory is present with child sub directories and folders. The call to readdir is successful, We get segmentation fault while trying to read child files/directories.

Thank you for any leads. Note: This somehow works with 1.81 nightly.

Additional test case that fails on vxworks. Traversing the directories.

use std::path::Path;
use std::io;
use std::fs::read_dir;

fn traverse_all_recursive(path: &Path) -> io::Result<()> {
    println!("Read directory");
    let dirs = read_dir(path)?;
    println!("Directory read {:?}",dirs);
    for child in dirs {
        println!("Child {:?}",child);
        let child = child?;
        if child.file_type()?.is_dir() {
            println!("Step Into Child Directory: {:?}", child);
            traverse_all_recursive(&child.path())?;
        } else {
           println!("File Name found: {:?}",child)
        }
    } 
    Ok(())
}
fn main(){
    let args: Vec<String> = std::env::args().collect();
    let directory=&args[1];
    println!("Hello, start traversing {}",directory);
    let path = Path::new(directory);
    let result = traverse_all_recursive(path);
    println!("Result {:?} ",result);
}
workingjubilee commented 4 months ago

no idea. could you bisect it to a specific commit?

biabbas commented 4 months ago

no idea. could you bisect it to a specific commit?

Will try that. I suspect the segmentation fault is due to a type mismatch in directory entry structures.

compiler-errors commented 4 months ago

1.77

The current stable Rust is 1.79. If this bug isn't present on that version, I don't think we fix issues that are older than the current stable release, so I think this issue should just be closed?

workingjubilee commented 4 months ago

@biabbas specifically I'm interested in knowing which commit fixed this.

@compiler-errors I agree but given that @biabbas has started looking into making sure VxWorks actually functions, and given that severity of the failing case (segfault at runtime), I think confirming that the commit in question is one we would expect to actually fix the error, or if it just is masking it, would be good. There have been large refactors of parts of std::sys.

biabbas commented 2 months ago

Bisecting to a particular commit seems very difficult, as each bisection requires cross-compiling the sources. An example must then be created and run on the VxWorks image. Therefore, using higher versions seems like the better choice