-
Notifications
You must be signed in to change notification settings - Fork 10
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
Reduce the use of unsafe
in the ecosystem
#19
Comments
I think this is a nice goal! I guess it would be nice if we had some way to validate our results at the end of this year. I saw Cargo Geiger being mentioned somewhere and I think it is a very nice tool to use to verify our results. Maybe we could automatize running Cargo Geiger on the top X most downloaded crates on crates.io and store the results? This way we could see by how much unsafe statements would be reduced or increased. Personally I also think that if we focus on creating good (safe) abstractions of unsafe operations or provide safe alternatives that are just as performant the amount of unsafe usage will automatically go down. If we could succeed in creating such things, we would only have to point them out to crate authors. |
I don't have time to work on this right now, but here it is in case somebody else does: I recently came across some code in the image crate which uses I wonder if it would be possible to create a utility that allows doing this safely. I'm not sure exactly how it would work, but the idea would be to architect it so that you only modify the length once, and then allow read/write access to the initialized part of the vector while only allowing an |
I mentioned here (rust-secure-code/safety-dance#4 (comment)) that claxon seems to do something similar (https://github.com/ruuda/claxon/blob/cd82be35f413940ba446d2a19f10d74b86466487/src/metadata.rs#L459-L461) |
We're starting a project to address this, initial results are very promising: https://github.com/rust-secure-code/safety-dance |
I am working on geiger.rs (yeah I bought the domain...) that geigers everything in crates.io I also created a proposal to add hookpoints for metadata to link unsafe related blocks to Issues that can be checked against whether these are Closed status which could indicate someone has validated them It also allows better organisation and visibility at geiger.rs I can track the blobs and see if the issues are updated if the unsafe blobs are changed somehow and then bot-pester for the crate repo owner to re-check whether the linked issue needs to be re-opened |
That is very impressive, but also going to end up quite expensive to run, because there is a lot of code on crates.io and you will need to compile all of it. Also, there are security concerns because Cargo can run arbitrary code (e.g. proc macros, build scripts) during compilation. Something like https://github.com/avadacatavra/unsafe-unicorn would be a cheaper but less precise alternative. This completes for the latest version of every crate on crates.io within hours on a regular desktop, but performs only rather basic textual analysis. |
Many widely used libraries use unsafe code where it's not strictly necessary. Typically this is done for performance reasons, i.e. there are currently no safe abstractions to achieve the goal safely and efficiently. The goal here is to reduce or eliminate the use of unsafe code throughout the ecosystem where it is not strictly necessary without regressing correctness or performance.
The per-crate process for this looks roughly like this:
unsafe
is used in the first place.git blame
usually helps with that by identifying a commit where a specific line is introduced.We want to run a lot of crates through this, so we also have some coordination tasks:
The text was updated successfully, but these errors were encountered: