flate2-rs icon indicating copy to clipboard operation
flate2-rs copied to clipboard

Do not compile unsafe FFI code when using Rust backend

Open Shnatsel opened this issue 5 years ago • 2 comments

flate2 includes plenty of unsafe code that's only used for interaction C backends, and can be omitted from the Rust backend builds. We should use conditional compilation to leave it out of the build when it's not in use, so that any auditing or refactoring efforts can focus on the unsafe code that's actually executed.

For example, the entirety of src/ffi/c.rs can be left out of builds that use Rust backend only; this brings down the unsafe expression count from 107 to 43 according to cargo-geiger.

Shnatsel avatar Nov 01 '19 00:11 Shnatsel

I've taken a stab at this, but the easy solution from here didn't work (likely due to 2018 edition module changes), and the module reexport hack described here is a bit over my head.

Shnatsel avatar Nov 01 '19 00:11 Shnatsel

Has it been fixed in the current code? https://github.com/rust-lang/flate2-rs/blob/fe15e4da08b3433f427cd1d41c6a5ed80a621651/src/ffi/mod.rs#L37-L46

JohnTitor avatar May 07 '23 00:05 JohnTitor