Repository navigation
1.17.0 regression: loop mutable vs immutable alias. #41599
Description
Activity
Reduced test case:
fn parse<'b>(_r: *mut [&'b u8], _b: &'b u8) {} fn main() { let mut buf = 0u8; let mut headers = []; loop { {&mut buf;} parse(&mut headers, &buf); } }
Changing the type of
_rfrom*mut [&'b u8]to*mut [&'b u8; 0]causes 1.16.0 to emit error also. Is it possible this is in fact a soundness fix?Where is the
*coming from? Is&mut selfreally*mut Self?- addedregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
on Apr 28, 2017 cc @rust-lang/compiler
Looks like it could be related to #40319
Changing the type of
_rfrom*mut [&'b u8]to*mut [&'b u8; 0]causes 1.16.0 to emit error also. Is it possible this is in fact a soundness fix?Yupp! This is #40319, which fixed the slice case - it had accidentally been allowed before.
Reacted by djzin and kennytmPretty sure it is that - this compiles and runs on rust 1.16, and is clearly unsound
fn parse<'b>(r: &mut [&'b u8], b: &'b u8) { r[0] = b; } fn main() { let mut buf = 0u8; let mut headers = [&0]; parse(&mut headers, &buf); let immutable: [&u8; 1] = headers; assert_eq!(*immutable[0], 0); buf = 1; assert_eq!(*immutable[0], 1); }
What's with the
1.17.1in the title, btw? I can edit it but maybe it's intentional.- changed the title
[-]1.17.1 regression: loop mutable vs immutable alias.[/-][+]1.17.0 regression: loop mutable vs immutable alias.[/+]on Apr 28, 2017 Sorry. Just a typo.
Anyway, I don't get it.
res(line 58) holds immutable reference that is dropped at the end of loop scope, so why can't it be used on read (line 49)? Thanks for your help anyway!@dpc Well, the bug was found by a user of
httparse, see seanmonstar/httparse#34.
I believe the explanation is thatheaderswill actually contain pointers intobuf.Oh, so the lifetime
'ais spanning furhter than the loop itself... I see... Thanks.So I guess all is well. Closing. :)
https://github.com/dpc/mioco/blob/0a12aae802256468f30a43cde2689e8846176914/examples/http-server.rs#L47
This code compiles on 1.16.0, but errors on 1.17.0:
Reproduced and confirmed by another person on
#rust. I'm working on minimizing, but since it's late, I might not be able to deliver today.