Skip to content

Commit 860ebb3

Browse files
committed
Use safe transmute by default
Using the zerocopy crate, we can port all header conversions from pointer cast to safe transmutes. After this change, the code in `header.rs` does not use `unsafe` anymore when the `zerocopy` feature is activated. Since this adds a derive crate without feature addition as dependency, zerocopy is an optional (but on-by-default) dependency.
1 parent ac2aade commit 860ebb3

5 files changed

Lines changed: 261 additions & 34 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
- run: cargo hack check --all --ignore-private --each-feature --no-dev-deps
2828
- run: cargo check --all --all-targets --all-features
2929
- run: cargo test
30+
# Test without zerocopy
31+
- run: cargo test --no-default-features
3032
- run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
3133

3234
msrv:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.5.2
4+
5+
* Use safe transmutes from the zerocopy crate by default
6+
37
## 0.5.1
48

59
* Add test to reproduce issue in `impl Stream for Entries` causing filename truncation by @charliermarsh in https://github.com/astral-sh/tokio-tar/pull/41

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ portable-atomic = "1"
3030
rustc-hash = "2.1.0"
3131
tokio = { version = "1", features = ["fs", "io-util", "rt"] }
3232
tokio-stream = "0.1"
33+
zerocopy = { version = "0.8.23", features = ["derive"], optional = true }
3334

3435
[dev-dependencies]
3536
tempfile = "3"
@@ -40,7 +41,9 @@ xattr = { version = "1.0", optional = true }
4041
libc = "0.2"
4142

4243
[features]
43-
default = ["xattr"]
44+
default = ["xattr", "zerocopy"]
45+
# Use safe transmute for headers (otherwise, unsafe pointer casts are used)
46+
zerocopy = ["dep:zerocopy"]
4447

4548
[lib]
4649
name = "tokio_tar"

0 commit comments

Comments
 (0)