Skip to content

Loading and saving same metadata cause errors #93

@qarmin

Description

@qarmin

Simplified code

fn process_file(path: &Path, dir_broken: &Path) -> Result<bool, String> {
    panic::catch_unwind(|| {
        let data = read_file_vec(path)?;
        let ext = detect_ext_from_vec(&data).ok_or_else(|| "Failed to detect file type".to_string())?;
        let metadata = load_metadata_from_vec(&data, ext)?;

        let mut data_new = data.clone();
        match metadata.write_to_vec(&mut data_new, ext){
            Ok(()) => Ok(false),
            Err(e) => {
                eprintln!("File {} is broken: {}", path.display(), e);
                let extension = path.extension().unwrap().to_string_lossy();
                fs::copy(path, dir_broken.join(format!("{}.{extension}", random::<u128>())))
                    .map_err(|e| format!("Failed to copy broken file {}: {}", path.display(), e)).unwrap();
                Ok(true)
            }
        }
    }).unwrap_or_else(|e| {
        Err(format!("Panic occurred while processing {}: {:?}", path.display(), e))
    })
}

Project - same.zip

Usage

cargo run --release -- /path_to_gather_files /path_where_save_broken_files

Reading metadata and writing back the exact same metadata to the original file should always succeed, but this errors are reported:

failed to fill whole buffer

Broken files -Broken.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions