Skip to content

Commit

Permalink
Bugfix: unsafe precondition(s) violated: slice::from_raw_parts requir…
Browse files Browse the repository at this point in the history
…es the pointer to be aligned and non-null, and the total size of the slice not to exceed isize::MAX

#128
  • Loading branch information
evgenyigumnov authored and otavio committed Jul 16, 2024
1 parent 480de12 commit e3e3465
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

## [Unreleased] - ReleaseDate

* Bugfix: unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed isize::MAX [#129]

[#129] https://github.com/OSSystems/compress-tools-rs/pull/129

## [0.15.0] - 2024-07-02

* Raise MSRV to 1.65.0
* Add next_header() to ArchiveIterator [#122]
* Fix use slice::from_raw_parts only if size > 0 [#126]
* Add feature "static" to allow static linkage for unix/macos [#127]

[#122]: https://github.com/OSSystems/compress-tools-rs/pull/122
[#126]: https://github.com/OSSystems/compress-tools-rs/pull/126
[#127]: https://github.com/OSSystems/compress-tools-rs/pull/127
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ where
value => archive_result(value, archive_reader)?,
}

if size == 0 {
return Ok(written);
}

let content = slice::from_raw_parts(buffer as *const u8, size);
target.write_all(content)?;
written += size;
Expand Down
Binary file added tests/fixtures/slice_from_raw_parts.zip
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,3 +854,10 @@ fn iterate_archive_with_filter_path() {
"filtered file list inside the archive did not match"
);
}

#[test]
fn test_slice_from_raw_parts() {
let mut source = std::fs::File::open("tests/fixtures/slice_from_raw_parts.zip").unwrap();
let mut outfile = tempfile::NamedTempFile::new().unwrap();
uncompress_archive_file(&mut source, &mut outfile, "1/2/1.txt").unwrap();
}

0 comments on commit e3e3465

Please sign in to comment.