Skip to content

Commit

Permalink
core: Fix XDVDFSFilesystem buffer copy size limit (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
antangelo authored Sep 7, 2023
1 parent ab0dc77 commit c4bc86a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
/Cargo.lock
*.iso
*.xiso
*.cso
*.ciso
**/dist/**
**/*.log
19 changes: 7 additions & 12 deletions xdvdfs-core/src/write/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,15 @@ where
let buf_size = buf.len() as u32;
let size = dirent.node.dirent.data.size;

// TODO: Find a way to specialize this for Files, where more efficient std::io::copy
// routines can be used (specifically on Linux)
let mut copied = 0;
while copied < size {
let to_copy = core::cmp::min(buf_size, size - copied);
let slice = &mut buf[0..to_copy.try_into().unwrap()];
let to_copy = core::cmp::min(buf_size, size);
let slice = &mut buf[0..to_copy.try_into().unwrap()];

let read_offset = dirent.node.dirent.data.offset(offset as u32 + copied)?;
self.dev.read(read_offset, slice).await?;
copied += to_copy;
}
let read_offset = dirent.node.dirent.data.offset(offset as u32)?;
self.dev.read(read_offset, slice).await?;

assert_eq!(copied, size);
Ok(size as u64)
assert!(to_copy <= buf_size);
buf[(to_copy as usize)..].fill(0);
Ok(buf_size as u64)
}
}

Expand Down

0 comments on commit c4bc86a

Please sign in to comment.