Subject
zerocopy-derive is a procedural-macro crate that provides custom derives for
traits defined in zerocopy (KnownLayout, Immutable, TryFromBytes,
FromZeros, FromBytes, IntoBytes, Unaligned, ByteHash, ByteEq,
SplitAt, plus the deprecated FromZeroes/AsBytes aliases). It contains no
runtime functionality; everything it produces is Rust source code that is
compiled into the downstream consumer's crate.
Methodology
The published crate contents were compared against the upstream Git repository
(commit recorded in .cargo_vcs_info.json) using diff -r. All Rust files
under src/ (lib.rs, util.rs, repr.rs, and the five modules in
src/derive/) were read in full. The test surface was surveyed (33 integration
test files under tests/, a UI/trybuild test harness, and ~960 lines of
in-source expansion tests under src/output_tests/ covering 34 expected-output
files). The source was searched for uses of unsafe, std::, network,
filesystem, process, environment, and other capabilities. Dependency declarations
in Cargo.toml were reviewed. No code was compiled or executed during the audit.
Results
The published crate matches the upstream repository: source files and tests are
byte-identical except for tests/enum_from_bytes.rs, which is deliberately
excluded via the manifest's exclude list. Cargo's normal additions
(.cargo_vcs_info.json, Cargo.lock, the normalised Cargo.toml, and
Cargo.toml.orig) are present and Cargo.toml.orig matches the upstream
Cargo.toml byte-for-byte.
The crate ships no binary artefacts (justifying has-binaries) and no
build.rs. The [lib] proc-macro = true declaration alone justifies
has-build-exec: proc macros execute on every downstream consumer's machine at
compile time. No Command::new, network client, or filesystem write reachable
from a proc-macro entry point was found, supporting build-exec-no-network and
build-exec-no-write-out; the proc-macro logic is a pure function from a
DeriveInput to a TokenStream, justifying build-exec-deterministic. The
only side-effecting code (std::env::var("ZEROCOPY_BLESS") and std::fs::write)
lives in src/output_tests/mod.rs, which is #[cfg(test)]-gated and not
reachable from the proc-macro entry points, justifying uses-filesystem,
uses-environment, and uses-exec.
Runtime dependencies are limited to proc-macro2, quote, and syn — the
standard procedural-macro stack — which justifies uses-network,
uses-concurrency, uses-crypto, and the implementation claims (impl-crypto,
impl-parser, impl-interpreter, impl-jit, impl-protocol, impl-datastructure,
impl-algorithm, impl-concurrency): all parsing is delegated to syn, and the
crate's logic walks the resulting AST and emits token streams.
Inside the proc-macro's runtime code there is exactly one unsafe { ... }
block (src/derive/try_from_bytes.rs:683), which calls the unsafe fn
gen_trivial_is_bit_valid_unchecked. That function's body is itself safe Rust
— it returns a TokenStream. The unsafe keyword expresses a soundness
contract on the emitted code, namely that the surrounding type is in fact
FromBytes; the caller establishes this via the could_be_from_bytes check
immediately above. The contract is documented with a # Safety doc comment,
supporting unsafe-safe, unsafe-documented and unsafe-minimal. The crate
also emits a large quantity of unsafe impl and unsafe { ... } tokens for
the downstream consumer to compile; the correctness of those is exercised by
the 33 integration tests and the in-source expansion tests, which compare the
generated token streams against golden files (justifying unsafe-tested). No
behaviour suggesting malicious intent — typosquatting, payload obfuscation,
target-dependent payloads, data exfiltration — was observed, justifying
is-benign.
No findings were recorded.
The crate ships an integration test directory under tests/ (justifying has-integration-tests); in-source #[cfg(test)] modules cover the macro internals (justifying has-unit-tests). There is no proptest/quickcheck use and no fuzz/ harness in the published archive, justifying has-property-tests and has-fuzz-tests as false.
The macro expansion runs in the proc-macro sandbox with no I/O, no environment access, and no FFI, justifying build-exec-minimal, build-exec-safe, uses-jit, uses-interpreter, and has-install-exec.
Conclusion
zerocopy-derive is a focused procedural-macro crate. Its proc-macro runtime
is essentially a pure function from a parsed AST to a token stream; the single
real unsafe usage is trivial and documented. The audit surface is the
emitted code, which is well covered by the package's expansion tests and by
the downstream zerocopy test suite. No security, safety, correctness, or
quality issues warranting a finding were identified at this version.