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

Do not compile unsafe FFI code when using Rust backend #219

Open
Shnatsel opened this issue Nov 1, 2019 · 2 comments
Open

Do not compile unsafe FFI code when using Rust backend #219

Shnatsel opened this issue Nov 1, 2019 · 2 comments

Comments

@Shnatsel
Copy link
Member

Shnatsel commented Nov 1, 2019

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
Copy link
Member Author

Shnatsel commented Nov 1, 2019

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.

@JohnTitor
Copy link
Member

Has it been fixed in the current code?

flate2-rs/src/ffi/mod.rs

Lines 37 to 46 in fe15e4d

// Default to Rust implementation unless explicitly opted in to a different backend.
#[cfg(feature = "any_zlib")]
mod c;
#[cfg(feature = "any_zlib")]
pub use self::c::*;
#[cfg(not(feature = "any_zlib"))]
mod rust;
#[cfg(not(feature = "any_zlib"))]
pub use self::rust::*;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants