News for hackers. Stuff that matters.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by rvz on Saturday June 13, 2020 @01:54PM (#23511234)
> The Rust community really needs to take care not to become an echo chamber.

Exactly. The language has been proven to be stable, however a valid argument is the unsoundness risks of a project when they begin to depend on lots of third-party crates.

The moment one imports a crate or third party dependency into their project, unless the dependency explicitly specifies the lack of unsafe{}, all bets are off on the 'safety guarantees', especially when 'that crate' is used in multiple projects.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by staticassertion on Saturday June 13, 2020 @01:59PM (#23511270)
"All bets are off" is an insane way to characterize this. IF a project is 99.99% safe code and has one unsafe dependency that is a massive difference from a project that is 100% unsafe. The surface area of the project that may be vulnerable is going to be relatively tiny.

As for an echo chamber, yeah the Rust community downvotes way too much. I find myself upvoting just to counter it.

But the downvoted comments here are legitimately bad. Someone being pedantic about the 70%, and being wrong, and another person calling this propaganda.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by bjourne on Saturday June 13, 2020 @04:40PM (#23512505)
Rust doesn't check for numerical over and underflows unless you run in debug mode which almost no one does because it is about two times slower than release mode. I.e. Rust doesn't live up to the safety standards many programmers coming from dynamic languages are used to where over and underflows are checked.

Many people in the Rust community appear to be unaware of this. Which is actually a big deal. Many of the bugs with the most catastrophic consequences are caused by over and underflows. Consider for example a gas pedal indicator kept as an unsigned that underflows causing the indicator to reach its maximum value.

If safety was my primary concern, I wouldn't choose C++ but I wouldn't choose Rust either.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by smitop on Saturday June 13, 2020 @05:33PM (#23512941)
You can pass "-C overflow-checks=on" to rustc to generate an optimized build with over/underflow checks enabled, even in a release build. Also, note that over/underflow behavior is defined to always be two's compliment wrapping when overflow checks are disabled.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by staticassertion on Saturday June 13, 2020 @05:46PM (#23513055)
> Rust doesn't check for numerical over and underflows unless you run in debug mode which almost no one does because it is about two times slower than release mode.

Totally, I wish Rust could express over/underflows better!

> Rust doesn't live up to the safety standards many programmers coming from dynamic languages are used to where over and underflows are checked.

> Rust doesn't live up to the safety standards many programmers coming from dynamic languages are used to where over and underflows are checked.

Yeah, that's possible. Thought it won't lead to unsafety, it is definitely a gotcha.

> Many people in the Rust community appear to be unaware of this. Which is actually a big deal.

Maybe, not sure.

> If safety was my primary concern, I wouldn't choose C++ but I wouldn't choose Rust either.

Really depends on the goals and constraints, of course. I'd be really concerned about using rust where an integer overflow could kill someone. I'd be really happy to use rust where a program crashing is totally acceptable, but exploitability isn't.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by acje on Sunday June 14, 2020 @12:04PM (#23518760)
Rust is memory safe, not infallible. Catching more runtime errors is a something rust can improve on. Erlang being one example of a strategy.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by zozbot234 on Saturday June 13, 2020 @02:10PM (#23511358)
> "All bets are off" is an insane way to characterize this.

Well, it depends. If the unsafe{} code is also unsound, then "all bets are off" is quite correct because you can't assume memory safety or lack of UB, even in your own code. In practice, you can use cargo-geiger to warn about crates that internally rely on unsafe code, and cargo-audit will warn about known security issues (including but not limited to unsoundness and memory-unsafety).

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by staticassertion on Saturday June 13, 2020 @02:24PM (#23511468)
> then "all bets are off" is quite correct because you can't assume memory safety or lack of UB, even in your own code.

The problem with "All bets are off" is it's not meaningful. What does that mean? It's so vague.

Lots of unsafe code is safe. Lots of UB is not exploitable. I can link to a vulnerable crate and not be vulnerable.

Can there be an exploitable bug in rust code? Yeah, sure. But saying "all bets are off" gives the impression of "why even bother if you link to unsafe code", which is absurd. Yeah, we should strive for more safe code, audit unsafe code, be very cautious about using it, but "all bets are off" come on.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by nilkn on Saturday June 13, 2020 @02:33PM (#23511540)
> Lots of unsafe code is safe.

This seems like a weird statement to make to me when defending Rust simultaneously. The whole selling point of Rust is that it's supposed to let you write provably safe code. When "unsafe" is used, what you're writing can no longer be proven as safe by the compiler. Maybe you've convinced yourself it's actually safe via some other argument, but people have been convincing themselves that their code is memory safe for decades and they're often wrong. More insidiously, relying on anything in Rust that uses "unsafe" makes it seem like the compiler is proving your own code is safe, but that is no longer true.

With that said, I don't really disagree with what I think your main point is. But seeing unsafe code in Rust is similar to seeing unsafePerformIO in Haskell libraries. Both of these are much more common than the languages' respective evangelists would have you believe, and at some point it actually does start to call into question whether the languages are successful at their basic design goals. (Spoiler: I believe that they are successful more than they are not, and even in the face of the proliferation of "unsafe" code in both languages, they're still worth using.)

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by staticassertion on Saturday June 13, 2020 @03:14PM (#23511876)
> The whole selling point of Rust is that it's supposed to let you write provably safe code.

I disagree. A significant purpose of rust is to encapsulate unsafe code, and provide safe abstractions. Lots of unsafe code is safe - most of it, even, I'd bet.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by nilkn on Saturday June 13, 2020 @03:23PM (#23511942)
> Lots of unsafe code is safe

I mean this with the greatest possible respect, but you replied by simply restating verbatim the quote that I originally responded to, so I'll just point you to my previous post.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by SAI_Peregrinus on Saturday June 13, 2020 @03:54PM (#23512181)
`unsafe` the keyword vs unsafe the concept. Lots of `unsafe` code is safe when used through a safe wrapper. Verifying that is the duty of the programmer. The compiler can't prove it, but quite often the programmer can.

IMO it's good practice to provide a comment with such proof for every `unsafe` block.

So `unsafe` does not imply unsound, but unsound does imply `unsafe`.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by staticassertion on Saturday June 13, 2020 @04:30PM (#23512425)
This is what I was trying to say. Unsafe doesn't imply exploitability, at all.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by staticassertion on Saturday June 13, 2020 @03:25PM (#23511958)
Sorry if I misunderstood your post then.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by zozbot234 on Saturday June 13, 2020 @02:43PM (#23511631)
The compiler has very limited "proof" capabilities even in principle, especially wrt. unsafe{} code. From a principled POV it would be nice to be able to provide a formal, compiler-checked proof that some block of code that has to rely on "unsafe" operations doesn't actually violate the language safety guarantees and can be wrapped safely. But this will have to depend on a formal model of "unsafe" itself which is still lacking. And it wouldn't even help for things like FFI, which involves calls into outside code for which the semantics are not formally known.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by saagarjha on Saturday June 13, 2020 @02:28PM (#23511496)
Well, there's two interpretations of "all bets are off". One is the runtime one, which is if you have a bug in unsafe code, then it is possible that all the other code in your program is safe but you're still totally out of luck because it can invalidate every guarantee. However, from an auditing perspective, the only code you need to look at for memory safety issues is that particular snippet, so you're in a much better position from that perspective.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by renewiltord on Saturday June 13, 2020 @03:30PM (#23512004)
"All bets are off" is not an engineering way to look at the problem imho. You alter your risk tolerance with the benefit gained. It's just trade-offs and the ability to do that is good.

I'm not going to argue you should use rust or not use rust but I think the state space is not binary and people reading will benefit from that.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by chc on Saturday June 13, 2020 @03:12PM (#23511866)
This is true, but it's also something the Rust community discusses all the time, along with what they can do about it. It seems like a huge leap to the conclusion that the Rust community is an echo chamber because some middlebrow dismissals got downvoted on Hacker News.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by entha_saava on Saturday June 13, 2020 @11:45PM (#23514922)
Even legitimate criticisms get downvoted or countered with dishonest marketing speech like 'borrow checker doesn't matter'.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by phkahler on Saturday June 13, 2020 @02:16PM (#23511404)
IMO crates are the biggest danger to Rust. It may very easily turn into the next NPM.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by saagarjha on Saturday June 13, 2020 @02:30PM (#23511509)
I think an even more problematic corollary is the desire to put nothing in the standard library, which cause the proliferation of crates that are the "standard" way of doing things but don't really have the guarantees/benefits that come with being part of "the" standard library.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by losvedir on Saturday June 13, 2020 @06:04PM (#23513198)
Yeah, I agree with this.

I see it kind of like Go's lack of generics, in a strange way. With Go, no one was explicitly "anti-generics", it's just the core team couldn't find a design they liked, and as time went on it became sort of a meme. "Go is opposed to generics." "No, here's that blog post by Russ Cox about finding a way to implement them." Etc, etc.

Similarly, the rust core team was afraid to settle on designs for certain libraries, pointing out things like python's various standard library HTTP modules, and at least "for now" shunting a lot of functionality out into the ecosystem. When you have limited manpower, this makes sense, but I think a lot of people have since rationalized that decision as philosophically the right thing to do, not just a way of prioritizing development work.

In other words, I feel like it's a case of a smart tactical decision growing into an identity.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by oefrha on Saturday June 13, 2020 @02:47PM (#23511663)
The saddest example I’ve come across so far is the lack of strftime, or any way to even print a clock time / date time in std. Even JavaScript has that. In a supposedly way past 1.0 language one has to rely on 0.x third party libraries to do even the most basic things.

Disclosure: only dabbled in Rust a bit, currently maintain two crates of some traction.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by Cyph0n on Saturday June 13, 2020 @03:03PM (#23511795)
The rand and regex crates are two other examples. I would also prefer to have bindgen in the standard library.

I’d love to use Rust in the OS I work on, but integrating our build system with Cargo and dealing with external crates is a huge obstacle.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by JoshTriplett on Saturday June 13, 2020 @04:57PM (#23512669)
> I would also prefer to have bindgen in the standard library.

That's a challenging one. I'd like to have native support for C integration as well, but we'll have to balance that with the stability of the corresponding clang interfaces, and the requirement to ship extra libraries that the Rust toolchain doesn't currently ship.

Working on it, though.

> The rand and regex crates are two other examples.

rand I'd agree with, though it would need paring down to not have as many dependencies. For regex, there are multiple tradeoffs to be made; for instance, the most popular regex crate is fast and does most of what people want but doesn't have backreferences or lookahead/lookbehind assertions.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by oefrha on Sunday June 14, 2020 @12:08AM (#23515047)
Question: is bindgen std quality yet? It seems there are still largely unsolved problems, e.g. https://github.com/rust-lang/rust-bindgen/issues/1549 which is causing hundreds of warnings in a -sys crate of mine and for which I have no recourse.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by Cyph0n on Saturday June 13, 2020 @11:52PM (#23514956)
> the requirement to ship extra libraries that the Rust toolchain doesn't currently ship.

Ah, that's something I did not consider...

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by petree on Saturday June 13, 2020 @03:53PM (#23512176)
I think the issue there is that versions are arbitrary and being able to tell when a library is 1.0 is a non-decidable problem. There are lots of 0.x crates which are stable and feel feature complete, but aren't specifically versioned as 1.0.

I would actually prefer if the Rust std would not include functionality that's not essential, for example sockets don't seem essential and the standard library does not implement them in a particularly complete and well thought out manner either IMHO.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by zozbot234 on Saturday June 13, 2020 @02:36PM (#23511565)
It would indeed be nice to have some sort of middle ground, where a selection of outstanding-quality crates can be officially "endorsed" by the Rust development team, but the endorsement can be withdrawn freely if something better comes along. C++ has something like this via Boost, and Haskell has their Haskell Platform, so it's not a new idea.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by saagarjha on Saturday June 13, 2020 @02:50PM (#23511691)
Actually, I am looking for more than this because I think Rust actually has a number of libraries that I think function fairly similarly to Boost. What I really want is the language committing to a library that is available without a third-party dependency, basically under a "linking exception" to be extremely close to "use however you want", supported by the people developing the language, designed alongside the language to remain ergonomic, with support that is tied to the language, … Personally, I consider this to be a very valuable feature from a programming language. Having a "pretty good" solution available "for free" is immensely value compared to having to go look online for every little thing, evaluate the landscape, audit it, ensure the licensing matches, consider whether will remain supported, and try to work around its idiosyncrasies.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by steveklabnik on Saturday June 13, 2020 @02:40PM (#23511607)
The Rust teams do maintain some crates outside of the standard library.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by nicoburns on Saturday June 13, 2020 @03:14PM (#23511874)
I think the proposal is specifically to bless a set of crates (that may include those developed by Rust teams, but probably also others such as regex).

Being in std implies some kind of quality standard, but it also implies no backwards incompatible changes. A set of libraries blessed by a trusted group could give you the quality standard without constraining backwards compatibility.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by steveklabnik on Saturday June 13, 2020 @03:24PM (#23511953)
Regex is one of those crates.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by jfkebwjsbx on Saturday June 13, 2020 @03:43PM (#23512108)
No, they don’t. If the Rust team maintains a crate officially and they will always do so (for reasonable values of "always"), then it is part of the standard library. Otherwise, it isn’t.

It is as simple as that. When serious, important projects depend on a standard library is because they want those guarantees. Having some members of Rust work on some crates does not give anyone those guarantees.

Which is why all those crates must be in std, or declare that the standard library is a set of crates (including core, std and others).

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by Someone on Saturday June 13, 2020 @04:56PM (#23512657)
I don’t see how that follows. Rust could easily have a (small) standard library that is guaranteed to be present everywhere and any of a number of optional libraries that are maintained by the same team that builds the compiler and the standard library.

That’s what java spent years on getting (https://www.oracle.com/corporate/features/understanding-java...), and I think that’s the way to go for any language. It prevents the standard library from bloating, yet provides quality libraries that can be trusted. It also allows some implementations to be standard without providing all the bells and whistles. That can be useful on small platforms, and allows for ‘heavier’ optional libraries (for example a SVG renderer, PDF parser, etc)

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by steveklabnik on Saturday June 13, 2020 @03:47PM (#23512131)
... I don’t see how that possibly follows. Not everything the project does is the standard library. The compiler, rustup, all kinds of tools.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by Buttons840 on Saturday June 13, 2020 @04:02PM (#23512243)
> [crates may turn into the next NPM]

Can't cargo refer to arbitrary git repos or even just plain directories? I don't see how it's any different from C or C++ in that case.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by losvedir on Saturday June 13, 2020 @06:25PM (#23513350)
It can, but then so can ruby's Bundler and elixir's Hex. But neither of them have the same issues as npm. I think npm's issues arise from a culture of making lots and lots of tiny dependencies, probably spawned by JS's anemic standard library.

At work, we have a number of Phoenix web apps with JS frontends. Looking at one randomly, there's... checking... 48 elixir dependencies and... checking... 911!! JS ones. I have to spend literally hours every week keeping those stupid JS dependencies up to date across our apps. The churn is enormous.

I think the fear is that as long as rust keeps its standard library small, a culture may develop to have more and more in the crate ecosystem, which proves to be a huge maintenance burden, as those are freer to update in breaking ways, and cross-depend on each other.

Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by jononor on Sunday June 14, 2020 @07:51AM (#23517007)
I think NPM obsession with small libraries comes from the lack of an decent optimizing compiler that can remove/not-include unused code, combined with a deployment scenario (frontend) where code size matters.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by steveklabnik on Saturday June 13, 2020 @04:09PM (#23512285)
It can, yes.
Re:Microsoft: Rust Is the Industry’s ‘Best Chance’ at Safe S... by entha_saava on Saturday June 13, 2020 @11:47PM (#23514929)
Except npm has order of magnitude more users.