Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uplazy::Lazy<T> having public fields is unsound. #105
Comments
eddyb
referenced this issue
Jun 28, 2018
Merged
Automatically use the allocation-free API for Rust 1.27.0+. #103
This comment has been minimized.
This comment has been minimized.
|
Hmm, this is pretty subtle... I'd be suspicious of any case that uses Still, I think we should patch out the soundness hole if we can. |
This comment has been minimized.
This comment has been minimized.
|
A crater run is possible for this. Is #103 the branch with the change? |
This comment has been minimized.
This comment has been minimized.
|
@pietroalbini Sounds good! We haven't got a branch with the change just yet, should we give you a ping when there is one ready? |
This comment has been minimized.
This comment has been minimized.
|
@KodrAus yes, thanks! |
This comment has been minimized.
This comment has been minimized.
|
@KodrAus Are you working on this, or should I open a PR? |
This comment has been minimized.
This comment has been minimized.
|
I'll work on this and include it with #103. |
This comment has been minimized.
This comment has been minimized.
|
@pietroalbini Alrighty, we've got a patch ready now in 0463a90 |
This comment has been minimized.
This comment has been minimized.
|
Friendly ping @pietroalbini Do you think the release team will have some bandwidth for a crater run on our |
This comment has been minimized.
This comment has been minimized.
|
Uh, woops! Totally forgot about this! Crater run started, it should be finished in a bit more than a day. |
This comment has been minimized.
This comment has been minimized.
|
No worries :) Thanks again @pietroalbini |
This comment has been minimized.
This comment has been minimized.
|
Hi @KodrAus (crater requester)! Crater results are at: https://cargobomb-reports.s3.amazonaws.com/lazy_static-1/index.html. 'Blacklisted' crates (spurious failures etc) can be found here. If you see any spurious failures not on the list, please make a PR against that file. (interested observers: Crater is a tool for testing the impact of changes on parts of the Rust ecosystem. You can find out more at the repo if you're curious) |
This comment has been minimized.
This comment has been minimized.
|
In other news, no regressions |
This comment has been minimized.
This comment has been minimized.
|
Thanks @pietroalbini! I appreciate your effort executing and examining the crater run |
This comment has been minimized.
This comment has been minimized.
|
Can we close this? #103 made the fields of |
eddyb commentedJun 28, 2018
•
edited
While normally only used within the
lazy_staticmacro, the type and its fields need to be public, at least for the oldmacro_rulesmacros. This poses both a safety (the fields are used in unsafe ways) and stability hazard (changing implementation details is technically breaking).Because
Lazy::gettakes&'static mut self, it's hard to abuse (static mutitself is unsafe, so it doesn't really count here), butBox::leakdoes let you create a&'static mutat runtime, so you could, in theory, leak aLazy<T>, trigger thecall_oncemanually, then callLazy::get, which will return an invalid reference to aT(since no actual initialization occurred).To construct a
Lazy<T>to initialize the static in the macro, you can use associated consts (since 1.20):This way, the fields can be made private (we should try a crater run if possible - cc @kennytm @Mark-Simulacrum - just to make sure nobody was using the
Lazytype themselves).