4 ms·
Interestingly, this release fixes an undefined behavior bug in Rust code. "CVE-2020-15254: Undefined behavior in bounded channel of crossbeam rust crate" marke
by blub 6y ago
Interestingly, this release fixes an undefined behavior bug in Rust code.
"CVE-2020-15254: Undefined behavior in bounded channel of crossbeam rust crate" marked as high.
- coliveira 6y agoSo now we see undefined behavior rearing its head on Rust too... I wonder how long until it gets to where C++ is.
- otabdeveloper4 6y ago"Undefined behavior" isn't something that language designers put in because they're dumb, it's a necessary consequence of having many compiler implementations and supported platforms. Once an alternative Rust compiler comes onto the scene, the language will necessarily fragment too.
- est31 6y agoAnother large reason for undefined behaviour is to allow for optimizations. The optimizer of a particular compiler version is well defined by the compiler's source code and binary. But in order to be able to ever change the optimizer, you need to have undefined behaviour in the language specification.
- ensiferum 6y agoUndefined behaviours are the accidental outcome when a program fails to be well formed. Nobody who writes compilers goes out there thinking that undefined behavior is the key that let's them optimize code to run faster.
- est31 6y agohttps://en.wikipedia.org/wiki/Undefined_behavior#Benefits https://en.wikipedia.org/wiki/Undefined_behavior#Benefits > Documenting an operation as undefined behavior allows compilers to assume that this operation will never happen in a conforming program. This gives the compiler more information about the code and this information can lead to more optimization opportunities.
- ensiferum 6y agoYes exactly the requirement that program is "well formed" is what leads to optimization opportunities. Not its "ill formedness". Nobody writes optimizations thinking "this program is ill formed I can enable this and that optimization" but exactly the reverse. "This program is well formed so I can enable some optimization."
- est31 6y agoI think we are talking past each other. When I said "undefined behaviour" above, I meant the concept of it. The fact that the language spec has undefined behaviour is what enables the compiler to make assumptions. The language spec could for example say that out of bounds indexing in an array is defined behaviour, and defined to raise a trap. But implementing that would slow down a lot of code. You refer to the ill formed code itself that violates the language specification. That's not what I meant. Yes, the fact that this code becomes garbage is a side effect of the optimizer's assumption that code is always well formed, instead of some arcane idea of punishing people who don't follow an arbitrary specification. I think we both agree.
- cesarb 6y agoThis is not a new thing, whenever you use the "unsafe" keyword you have to pay attention to undefined behavior. For instance, having two "mut" references at the same time to the same memory has always been undefined behavior in Rust; you cannot construct them without "unsafe", but it's very easy to do with "unsafe" (just cast to a pointer and back). In the same way, "unsafe" allows you to construct references with an arbitrary lifetime, and many other potentially-undefined things; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html https://doc.rust-lang.org/reference/behavior-considered-unde... for a list. I don't think Rust will "get to where C++ is" (whatever that means), because (outside of compiler bugs) you will not have undefined behavior unless you use "unsafe", and most Rust code doesn't use "unsafe"; the pieces that do use "unsafe" can be carefully audited (instead of auditing the whole code).
- Xylakant 6y agoUndefined behavior on rust isn’t anything new, there’s even a section in the book about it. https://doc.rust-lang.org/beta/reference/behavior-considered-undefined.html https://doc.rust-lang.org/beta/reference/behavior-considered... The issue referenced happens in an unsafe code block, see this patch. https://github.com/crossbeam-rs/crossbeam/pull/533/commits/be327d581e8434a2ba41b74affc915f42d8abfcd https://github.com/crossbeam-rs/crossbeam/pull/533/commits/b... There is no promise that Rust protects programmers from making mistakes in code marked as unsafe.