Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use slice::from_raw_parts only if size > 0 #126

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
## [Unreleased] - ReleaseDate

* Raise MSRV to 1.63.0
* Fix use slice::from_raw_parts only if size > 0 [#126]

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

## [0.14.3] - 2023-05-26

Expand Down
15 changes: 11 additions & 4 deletions src/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,17 @@ impl<R: Read + Seek> ArchiveIterator<R> {
{
ffi::ARCHIVE_EOF => ArchiveContents::EndOfEntry,
ffi::ARCHIVE_OK | ffi::ARCHIVE_WARN => {
let content = slice::from_raw_parts(buffer as *const u8, size);
let write = target.write_all(content);
if let Err(e) = write {
ArchiveContents::Err(e.into())
if size > 0 {
// fixes: (as buffer is null then) 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`
let content = slice::from_raw_parts(buffer as *const u8, size);
let write = target.write_all(content);
if let Err(e) = write {
ArchiveContents::Err(e.into())
} else {
ArchiveContents::DataChunk(target)
}
} else {
ArchiveContents::DataChunk(target)
}
Expand Down
Loading