Skip to content

Commit f87431d

Browse files
committed
Add safety comments
Document unsafe blocks in the crate, all of which correspond to the same use case. This fixes issue #6. Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com>
1 parent e2508f6 commit f87431d

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ impl PackParams {
9595
ar.write_file(&pfile)?;
9696
}
9797
_ => {
98+
// SAFETY: assume user-provided file is not being modified.
99+
// Worst case scenario, we read the wrong bytes.
98100
let file_data = unsafe { Mmap::map(&file) }?;
99101
let pfile = PackItFile::new(dst_path, &file_data)?;
100102
ar.write_file(&pfile)?;
@@ -163,6 +165,8 @@ impl UnpackParams {
163165
fn run(&self) -> PackItResult<()> {
164166
// Prepare the decoder
165167
let file = fs::File::open(&self.input)?;
168+
// SAFETY: assume user-provided file is not being modified.
169+
// Worst case scenario, we read the wrong bytes.
166170
let mem = unsafe { Mmap::map(&file) }?;
167171
let dec = PackItArchiveDecoder::load(&mem)?;
168172

@@ -223,6 +227,8 @@ struct ListParams {
223227
impl ListParams {
224228
fn run(&self) -> PackItResult<()> {
225229
let file = fs::File::open(&self.input)?;
230+
// SAFETY: assume user-provided file is not being modified.
231+
// Worst case scenario, we read the wrong bytes.
226232
let mem = unsafe { Mmap::map(&file) }?;
227233
let dec = PackItArchiveDecoder::load(&mem)?;
228234
for file in dec {

0 commit comments

Comments
 (0)