| ▲ | 11 year old unsoundness bugs found in Rust borrow checker(github.com) |
| 334 points by formerly_proven 3 hours ago | 129 comments |
| |
|
| ▲ | mrkeen 3 hours ago | parent | next [-] |
| Type systems are hard! Check out https://counterexamples.org/ I gave it a quick scan for Rust examples; there are 11 samples among the following pages: https://counterexamples.org/eventually-nothing.html
https://counterexamples.org/mutable-matching.html
https://counterexamples.org/selfishness.html
https://counterexamples.org/scope-escape.html
https://counterexamples.org/nearly-universal.html
The first thing I always look for is mutability (combined with some other tricky feature), e.g. "Now it's a Just(3):Maybe<Int>, now it's a Nothing:Maybe<Int>, now it's a Nothing:Maybe<String>."I wonder if TFA's example could be reproduced without mutability. |
| |
| ▲ | codehero 22 minutes ago | parent | next [-] | | "Type systems are hard!"
As hard as its safety is pushed on us, not even Rust is free from hand waving. | | |
| ▲ | ahartmetz 15 minutes ago | parent | next [-] | | At least Rust has a chance to be largely correct because it has much greater effort per amount of code (in the compiler) invested into it than most any application code. | |
| ▲ | doodpants 6 minutes ago | parent | prev | next [-] | | I mean, Rust's whole shtick is safety, so that's really the only thing there is to "push" about the language. | |
| ▲ | caaqil 14 minutes ago | parent | prev [-] | | > not even Rust is free from hand waving. It is moral though, so who cares really. |
| |
| ▲ | vrighter 2 hours ago | parent | prev [-] | | so what I take from this is that the rust compiler does not guarantee the stuff it claims to. Because new features of the type system is just being yolod instead of formally proven EDIT: I said new features of the type system and more importantly, their interactions with the ever growing list of other features, not new features in the compiler. Totally different things. The compiler could be perfectly implementing the wrong choice of algorithms in the first place. | | |
| ▲ | roblabla 2 hours ago | parent | next [-] | | There never was formal verification of the entire rust compiler, or even its complete borrow checker/type system. There has been verifications on _subsets_ of them. Also, a lot of those soundness issues aren't related to new features _at all_, but usually due to poor assumptions made in optimizations. The soundness bugs _are_ taken seriously though, and are slowly being patched out. A lot of the links in OP are now closed because Rust either changed how it generates code to avoid the issues, or fixed LLVM. | | | |
| ▲ | jeremyjh 2 hours ago | parent | prev | next [-] | | There is a massive possibility space between “yolo” and formal proof. Rust has substantial evidence of correctness. For example, unit tests and types. | | |
| ▲ | vrighter an hour ago | parent | next [-] | | That's verifying the implementation. The type system wasn't verified. It implements stuff perfectly, it has tests that prove it, but nobody formally verified that they perfectly implemented the correct algorithms | | |
| ▲ | bluGill 42 minutes ago | parent [-] | | Tests are not perfect, but they are a lot better than where we were in 1990. |
| |
| ▲ | carlmr an hour ago | parent | prev [-] | | Spot on, but this makes me think of a larger problem. You can be annoyed by Rust fanboys, sure, but the more annoying are the Rust haters, because the hate always comes from a place of ignorance. The hate only works if you don't go beyond a surface level understanding of Rust. E.g. a niche case on the borrow checker is slightly broken, so borrow checking doesn't make sense. Or the "oh but Rust needs unsafe, so it's just like C++". Yeah, but by that measure all of C++ is unsafe++, even unsafe has more guarantees than standard C++. Only if your whole understanding of the concept is that the keyword is called "unsafe", does that argument make sense. A bit of a rant, but if you hate Rust with a passion, ask yourself first where that opinion comes from and if it can stand on its own. In most cases it can't. | | |
| ▲ | krona an hour ago | parent | next [-] | | > You can be annoyed by Rust fanboys, sure, but the more annoying are the Rust haters, because the hate always comes from a place of ignorance. For what it's worth, Rust fanboys also seem just as vulnerable to their ignorance of C/C++ compiler extensions and tooling (e.g. sanitizers, bounds annotations, standard library hardening modes and so on.) which are just normal part of professional C/C++ use today. | | |
| ▲ | afdbcreid 26 minutes ago | parent [-] | | And are also woefully insufficient as proven in most sanitized & linted & fuzz-tested programs in existence (browsers and operating systems). | | |
| |
| ▲ | _flux an hour ago | parent | prev [-] | | I think the difference is here: - If a compiled C++ program has unsound behavior, the program needs to be fixed - If a compiled safe Rust program has unsound behavior, the compiler needs to be fixed | | |
| ▲ | jooops1 20 minutes ago | parent | next [-] | | That's not completely correct. If the Rust or C++ compiler has a bug in both cases either the compiler has to be fixed or the program can be adjusted to work around said compiler bug If possible. However, It's fair to argue that the Rust compiler makes more assertions and is more complex, which results in a larger error surface. | |
| ▲ | devmor 41 minutes ago | parent | prev [-] | | > If a compiled safe Rust program has unsound behavior, the compiler needs to be fixed Can you provide an example of such a program that can’t be fixed at the program level like a C++ example? | | |
| ▲ | _flux 38 minutes ago | parent [-] | | Sure, usually the program can be changed to avoid the issue, but the key here is that the Rust compiler is wrong and needs to be fixed. Once fixed, the actual program fix also falls in place, as it cannot be compiled anymore. |
|
|
|
| |
| ▲ | thfuran 2 hours ago | parent | prev | next [-] | | No mainstream compiler is formally proven. If you want a verified compiler, you pretty much have to choose between using a subset of standardml or a subset of C and the one proven compiler for each. | | |
| ▲ | vrighter an hour ago | parent | next [-] | | You're mistaking the semantics of the type system, from the implementation. I'm not talking about verifying the compiler. There's nothing to verify there.... literally. There is no spec to the language. By definition it is verified because the only verification you can do is tautological: "does this rust compiler do what this rust compiler does?" But the unsoundness is because the type system itself, abstractly, was not verified. Or the interactions between parts. I.e. If you verified the compiler you'll find that it implements the algorithms perfectly. But tells you nothing about whether those implemented algorithms, however perfectly implemented, actually provided those guarantees. | |
| ▲ | AnimalMuppet an hour ago | parent | prev [-] | | Wait, there's a proven subset of C? Can you point me to some info? | | |
| |
| ▲ | UncleMeat an hour ago | parent | prev | next [-] | | The Java type system is also unsound. That’s life. It is hard to do this fully correctly. In practice this never comes up. | | |
| ▲ | afdbcreid an hour ago | parent [-] | | While true, there are two important differences: 1) Unsoundnesses in Java's type system are checked at runtime. 2) They (or at least some) are intentional or at least won't-fix bugs. Both are not true for Rust. |
| |
| ▲ | cowlevel an hour ago | parent | prev | next [-] | | As you can see, this is a true statement, but HN really really really hates it for some reason. | |
| ▲ | csande17 2 hours ago | parent | prev [-] | | Yes. When people describe Rust as "a memory-safe programming language" they are describing an aspirational vision, and not a programming language that has actually been designed with sufficient rigor to guarantee memory safety. Any failure of rustc to actually guarantee this is just a bug in rustc itself, a failure to properly implement the Rust spec, because the closest thing Rust has to a spec is literally just the vague ideal that the compiler should guarantee safety somehow. Rust cannot fail, it can only be failed. | | |
| ▲ | DriverDaily an hour ago | parent | next [-] | | > Rust cannot fail, it can only be failed. “Please build the perfect system. Because I specified ‘perfect’ any flaws are due to your incomplete implementation, not my awful brief.” If the person writing the rust spec was a client I would have to drop them because they would be setting themselves up for dissatisfaction. | |
| ▲ | insanitybit an hour ago | parent | prev | next [-] | | I don't think the definition of "memory safe" has ever required full end to end stack conformance with a proof. Very few languages have achieved that, though some have. Most people call Java memory safe, C#, Python, Typescript, etc - all of those fall short of a formally verified, sound type system with a verified toolchain. | | |
| ▲ | afdbcreid an hour ago | parent [-] | | Not to talk about Go, which has intentional unchecked-at-runtime UB (data races) yet many argue to consider it memory safe (and I have a feeling that the same people arguing Rust isn't memory safe are also there. Just a feeling though). |
| |
| ▲ | UncleMeat an hour ago | parent | prev | next [-] | | Would you say the same thing about Java? It’s type system is also unsound. | | |
| ▲ | vrighter an hour ago | parent | next [-] | | but it isn't claiming to be saving you from things it can't prove it can either. | |
| ▲ | csande17 an hour ago | parent | prev [-] | | I'm not an expert on the Java specification, but my understanding is that Java as a language is well-defined enough that we can say things like "Java's type system is unsound", independently from any specific implementation of Java. You can't do that with Rust because "Rust's type system" is literally just the vague concept of "a type system that is safe". The implementation of this ideal in rustc can have flaws, but Rust itself cannot, because Rust itself has no flaws by definition. |
| |
| ▲ | lolakutty 2 hours ago | parent | prev [-] | | >Rust cannot fail, it can only be failed... Sweet. But why should anyone care.. |
|
|
|
|
| ▲ | GrantMoyer an hour ago | parent | prev | next [-] |
| It's surprising this bug went unnoticed for so long, but at least it's easy to fix, since it's not a bug with the type system itself; it's just a bug in the compiler. The compiler should always have been rejecting that code according to lifetime rules of Rust's type system, so the fix is to just make it reject the code, rather than having to change the fundamental rules of lifetimes. |
| |
| ▲ | WiSaGaN 35 minutes ago | parent | next [-] | | It's fascinating that this kind of bug is exactly you can't really avoid even when rust is supposedly to guard against. Rust mitigated this problem a lot in practice, but you can never be certain because of issues like this in practice. This is similar that a math proof that's already been peer reviewed and accepted as truth, may still be possible to be wrong, although the chance is very small but it's not zero. Epseicially when the complexity gets higher. | |
| ▲ | mav65 an hour ago | parent | prev [-] | | Not knowing anything about rust, the problem in these type of case is making it rejecting that bad code without also rejecting valid programs. But maybe this is indeed easy to fix, I don't know. | | |
| ▲ | bluGill 36 minutes ago | parent [-] | | There are no such valid programs. Proof by contradiction: A valid program would be exploiting undefined behavior in rust, but rust has no undefined behavior. Thus such a program must not exist. Now a program may appear to work before the fix, but it was never a valid Rust program. | | |
| ▲ | afdbcreid 22 minutes ago | parent [-] | | I can't tell if you are sarcastic, but in case you are not: By Rice's theorem you cannot be sound and complete, i.e. accept all valid programs and reject all invalid ones. Most languages choose to be sound but not complete, i.e. reject all invalid programs but also some valid ones (C and C++ are the notable exception, although most languages have escape hatches). GP was saying that the fix might reject valid programs that compile today. This is true for some existing soundness bugs, but not necessarily for this one specifically. |
|
|
|
|
| ▲ | lambdaone 2 hours ago | parent | prev | next [-] |
| Perhaps ironically, AI-based searching of the Rust compiler for bugs is likely to find more of these, pushing Rust closer and closer to the point of complete reliability. The eventual formalization of Rust and a creation of a formally proven compiler is presumably going to be the end point of this process. |
| |
| ▲ | stingraycharles an hour ago | parent | next [-] | | Why would that be ironic? AI is helping us find so many subtle bugs and isolate the root cause, it’s nearly perfect for this type of use case. | |
| ▲ | kimi 2 hours ago | parent | prev | next [-] | | Or we realize that it is not possible, and Rust accepts to be "just" a definitely safer C. | | |
| ▲ | wongarsu an hour ago | parent [-] | | There is a formally proven compiler for a large subset of C, so I don't see why formalizing (a large subset of) rust and making a formally proven compiler shouldn't be possible | | |
| ▲ | afdbcreid an hour ago | parent | next [-] | | Also unlike C, it should be possible to formalize all of Rust, not just a subset. For two reasons: Rust evolution (not initially but today) is strongly tied with formalizing it and the language team consults with formalization experts (which are part of the Rust project themselves) all the time (and formalization or semi-formalization projects are ongoing), and also the mathematical understanding of system languages itself has advanced. | | | |
| ▲ | afdbcreid an hour ago | parent | prev | next [-] | | There is a severe misunderstanding here. Beside being only a subset, CompCert definitely has UB. It just formalizes codegen for codebases not containing UB, which obviously won't be enough for Rust. | |
| ▲ | UncleMeat an hour ago | parent | prev [-] | | Because people want a performant optimizing compiler. |
|
| |
| ▲ | mi_lk an hour ago | parent | prev | next [-] | | What aspects of it are remotely ironic? | | |
| ▲ | jere 40 minutes ago | parent | next [-] | | Obviously, many people have viewed AI’s contribution to programming as just producing unreliable garbage. Yes, that’s an incomplete and tenuous belief, but that’s where the irony is. If you’re omniscient you don’t get to experience irony. | |
| ▲ | brzz an hour ago | parent | prev [-] | | Hey, if Alanis Morissette can make the same mistake… |
| |
| ▲ | bbor 2 hours ago | parent | prev | next [-] | | Until they find bugs in the formal proof program ;) https://www.lesswrong.com/posts/zHhGa3iQBQcdSifFL/a-critical... | | | |
| ▲ | malkia an hour ago | parent | prev | next [-] | | and what stops AI from "accidentally" writing code with such bugs? | | | |
| ▲ | lifeisloving an hour ago | parent | prev [-] | | I asked myself, How many comments to do I have to collapse before someone says something about AI. 3. I used to compare this hype to crypto hype, but its so much worse. Can we just try not to shove llms into every single conversation. Is there a hackernews type space where the word is banned? Even lobste.rs has this problem. I need some sort or way to just hide all content on certain sites where LLMs/AI are mentioned. | | |
| ▲ | streetfighter64 32 minutes ago | parent [-] | | I'm not a huge AI hype man, but I think you'll just have to accept it. It's a new useful tool, of course people are excited to apply it to everything. Like it or not, programming will become largely LLMs. And the comment you're replying to is actually making a pretty good case for where the use of LLMs is good: generating code to be formally verified. |
|
|
|
| ▲ | weinzierl 2 hours ago | parent | prev | next [-] |
| This is remarkable but not super unusual. There are more than 100 issues labeled unsound currently. Some are long standing but from what I understand the new trait solver will unblock fixes for some of them (but probably not the one in OP). |
| |
| ▲ | theemathas an hour ago | parent | next [-] | | Finding unsoundness bugs isn't the most unusual, yes. But this one is unusual in how simple the code that causes it can be (see the versions of the reproducer code in the comments). For other unsoundness bugs, the code would need to contort itself a lot to avoid the compiler checks. | |
| ▲ | rurban 21 minutes ago | parent | prev [-] | | Wait, shock! So you say rust is unsafe by default? | | |
| ▲ | weinzierl 9 minutes ago | parent [-] | | Not really. The idea is that safe Rust promises that you can't cause UB without unsafe. Unfortunately there are cases, where the current rust compiler implementation fails to keep that promise. These cases are all tracked as bugs and it's expected they'll be fixed eventually. AFAIK non of the known cases is unfixable, it just takes time and effort, sometime a lot. Also note that C++ does not make such promises in the first place, so the equivalent code there isn't a bug, it's just UB. |
|
|
|
| ▲ | gosen 22 minutes ago | parent | prev | next [-] |
| I'm sure we'll get more of those on other languages / frameworks too. I tend to believe that it's for good |
|
| ▲ | rurban 24 minutes ago | parent | prev | next [-] |
| And a fork fixed it before upstream rust :) |
|
| ▲ | randyrand 44 minutes ago | parent | prev | next [-] |
| I just wish Rust handled out of memory more gracefully like a normal error. |
| |
| ▲ | bluGill 32 minutes ago | parent [-] | | Why bother? Most systems these days have over commit and so you can never get an out of memory error. The OS will happily give you more and more RAM, and then when you try to use that memory kill a program (may or not be your program). The only out of memory error you can see is if you are trying to allocate more memory than the address space allows. This is so unlikely that nobody considers it worth bother to try to handle. |
|
|
| ▲ | shevy-java 13 minutes ago | parent | prev | next [-] |
| Poor Rustees no longer see the bugs due to the syntax noise! |
|
| ▲ | j4k0bfr 2 hours ago | parent | prev | next [-] |
| Took me a good couple minutes to wrap my head around. Man, what a nasty bug. I guess this specific use-case is rare. Time to see if any of the big libs are affected... |
| |
| ▲ | coliveira an hour ago | parent [-] | | A nasty and rare bug can and will be exploited once it is found. The only thing necessary is for malicious actors to start adding this case in innocent looking code and there you have. | | |
| ▲ | afdbcreid an hour ago | parent [-] | | That's a misunderstanding. This is not a security vulnerability and Rust explicitly does not defend from malicious programs, only from mistakes. This bug however is quite dangerous, because unlike many soundness bugs it seems plausible to hit by mistake. |
|
|
|
| ▲ | FuzzywarmWalnut 3 hours ago | parent | prev | next [-] |
| Worked on a variance-related lint once and the scary part is how rarely anyone writes down variance by hand, so bugs there just sit untested for a decade. |
| |
| ▲ | afdbcreid 18 minutes ago | parent [-] | | Nobody writes variance at hand in Rust because it's impossible (since before 1.0). You sometimes need to enforce stricter variance than the default (can cause unsoundness and is very subtle but actual unsoundness here is rare) or give more permissive variance (harder and also cannot cause unsoundness, just annoyance). When implementing the type system, however, variance does have to be treated with care. Historically it wasn't much, now it is. |
|
|
| ▲ | vincent-uden 3 hours ago | parent | prev | next [-] |
| What the hell. This is not the esoteric, crazy, impractical constellation I expected to find with a title like this. The minimal example is so simple and is definitely something you'd easily come across in normal code. |
| |
| ▲ | insanitybit 3 hours ago | parent | next [-] | | For a long time `loop {}` was undefined behavior. Lots of l-unsounds are really nuts but a few are not. The reality is that if this were actually code that people wrote, well, it wouldn't have sat around for a decade. | | |
| ▲ | masklinn an hour ago | parent [-] | | Afaik loop {} has never been UB, however because llvm started as a c++ compiled where it is, this has been causing miscompilations in rust and C for… nearly two decades (llvm issue 965). | | |
| ▲ | cowlevel an hour ago | parent [-] | | Since the Rust language is defined by the Rust compiler and has no other specification, if it's UB in the compiler then it's UB in the language. |
|
| |
| ▲ | fg137 2 hours ago | parent | prev | next [-] | | > is definitely something you'd easily come across in normal code. The fact that nobody reported this before means it's not, by definition. | | |
| ▲ | vincent-uden 44 minutes ago | parent [-] | | Not at all. There are way more valid lifetimes than the lifetime system of Rust can express. There are countless scenarios where you could accidentally use the unsound behaviour while not producing a segmentation fault because the lifetimes happens to be arranged such that no invalid memory access actually happened. A program isn't invalid just because it violates the ownership and borrowing rules of Rust. There are tons of programs in the world with shared, mutable access, devoid of Mutexes, Arcs and Locks that nonetheless are completely valid. | | |
| ▲ | fg137 27 minutes ago | parent [-] | | I think you are talking about a different problem and that has nothing to do with my comment. |
|
| |
| ▲ | LoganDark 3 hours ago | parent | prev | next [-] | | I wonder if the reason it works is because you'd easily come across it in normal code, and someone didn't realize that saving the effort of implementing a check for this would result in unsoundness. | | |
| ▲ | afdbcreid 20 minutes ago | parent [-] | | That's not how it works. rustc doesn't "check" for specific cases explicitly, the borrow checker (apparently at fault here by reports) has a set of rules that should reject invalid programs. So either one of the fundamental rules was broken (unlikely here from what I've heard), or some optimization caused the rules to not be implemented correctly. |
| |
| ▲ | jvanderbot 3 hours ago | parent | prev [-] | | Not really. I've worked with rust for 4 years, systems side, and never had to write a custom drop implementation. That's the gotcha here, not the rigamarole with the static+Send option type (which _would_ be something you'd encounter in prod). | | |
| ▲ | bryanlarsen 3 hours ago | parent | next [-] | | I've written dozens of custom Drop implementations. Well, many of them are named cleanup because of the async Drop mess in Rust, but... | | |
| ▲ | dwattttt an hour ago | parent | next [-] | | How many of them only conditionally implement Drop, based on a generic param lifetime? | | |
| ▲ | Xirdus an hour ago | parent [-] | | Why would you ever conditionally custom impl Drop? I don't think I've ever seen that pattern, and I can't think of a use case. |
| |
| ▲ | jvanderbot an hour ago | parent | prev [-] | | OK. That's good to know. I'm not sure why sharing our professional experience with this type of code is controversial, but here we are. |
| |
| ▲ | neysofu 2 hours ago | parent | prev | next [-] | | That's easily the exception rather than the rule. I've seen custom `Drop` implementations in almost every non-trivial Rust codebase I worked on. | |
| ▲ | gspr 2 hours ago | parent | prev | next [-] | | A custom `Drop` appears very quickly with FFI code. Suppose for example you interface with some C library that expects you to call a function to release some resources. | |
| ▲ | rvz an hour ago | parent | prev [-] | | Now we are at the phase where, Rust is “safe” but only if you use it “correctly” and without using X language feature or a custom Y feature. This is the problem when a language advertises with “guarantees” and it turns out it never had any due to many false assumptions by their promoters. So what other soundness bugs are there in the language that we need to know about? | | |
| ▲ | jvanderbot an hour ago | parent | next [-] | | I'm not defending rust here - a correctness bug invalidates the premise. But I am saying that I've never seen a custom drop in production. For some reason this is controversial, but it remains true. | | |
| ▲ | bryanlarsen an hour ago | parent | next [-] | | You said/implied 2 things: - you've never written a custom Drop - "Not really". Implying that your experience generalizes I've written a bunch of rust programs without custom Drop. I believe your first statement. There are large classes of programs that don't need it. There are also many that do. I think your statement says a lot more about what kind of programs you work on than about custom Drop not being common. People are downvoting the implication that custom Drop is not a common pattern. | |
| ▲ | cmrdporcupine an hour ago | parent | prev [-] | | Custom drops are all over the place. As others have said. But not custom drops that are doing variadic type stuff like this, usually. |
| |
| ▲ | cmrdporcupine an hour ago | parent | prev [-] | | No we're in a situation where a bug in the type checker was found and will be fixed and a new release will be made. That it took 11 years for someone to come across this is a fairly intense counterargument to your attempt to paint this as a language with dangerous footguns. |
|
|
|
|
| ▲ | MrBuddyCasino 3 hours ago | parent | prev | next [-] |
| The heart of the matter: struct Q<T: 'static>(Option<T>);
impl<T: 'static> Drop for Q<T> {
fn drop(&mut self) {
// Code in here has access to a non-'static &String
// but assumes that it's a &'static String
}
}
fn main() {
let l = String::new();
let mut q = Q(None);
q.0 = Some(&l);
}
I wonder if the certified compiler for safety critical uses (edit: Ferrocene) has the same issue. |
| |
| ▲ | 1718627440 2 hours ago | parent | next [-] | | Can someone ELI5 for people who don't know Rust (but e.g. C)? | | |
| ▲ | thinkharderdev an hour ago | parent [-] | | Rust is supposed to guarantee statically that a reference cannot outlive its referent. The `T: 'static` bound means that the value that Q holds must have a 'static lifetime (e.g. either be an owned value or a reference to a static value). So this program should not compile since a reference to l is not 'static. This code is unsound because rust will drop the string l before q so when the Q destructor runs the underlying string has already been freed yet we have a valid reference to it. | | |
| ▲ | 1718627440 an hour ago | parent | next [-] | | What does "q.0" and "Some(...)" mean? | | |
| ▲ | thinkharderdev an hour ago | parent | next [-] | | So Q is a "tuple-struct". In rust you can define a struct like struct Q<T> {
value: Option<T>
} with a named field or you can define it like struct<T> Q(Some<T>) which is the same struct layout but without an explicit name for the value. In that case, the field is implicitly names `0` So q.0 = Some(foo) is equivalent to q.value = Some(foo). The Some(..) is just one variant of the Option enum: enum Option<T> {
None,
Some(T)
} Option represents a value that may or may not be initialized. For uninitialized values you use the None variant and then you can initialize it to Some(value). The C rough equivalent would be struct Q {
void* value;
} struct Q q = q { NULL };
q->value = ... | |
| ▲ | cowlevel an hour ago | parent | prev | next [-] | | Some(...) is just constructor for an option type as seen in other languages e.g. java's Optional, haskell's Maybe, c++'s std::optional. I assume that it's needed here because the field can't start as a null pointer otherwise. Maybe the vulnerability still works if the field starts with one string value and swaps to a different string value, but having it start holding None made for a simpler demo. q.0 is the first field of q, which is anonymous. They could have just as well called it x and written q.x. | |
| ▲ | bonzini an hour ago | parent | prev [-] | | "Some(...)" means that this Option<T> does have a value of type T in it; "None" means it doesn't. "q.0" is not really needed, it's a struct with unnamed fields. Here is the same with named fields: struct Q<T: 'static> { pub x: Option<T> }
...
let l = String::new();
let mut q = Q { x: None };
q.x = Some(&l);
|
| |
| ▲ | 1718627440 an hour ago | parent | prev [-] | | So the equivalent in C would be: $ cat main.c
#include <stdlib.h>
#include <string.h>
struct Q {
/*@null@*/ /*@only@*/ char * t;
};
/*@only@*/
struct Q *
Q_new (/*@only@*/ char * t)
{
struct Q * q = malloc (sizeof *q);
q->t = t;
return q;
}
void
Q_set (struct Q * q, /*@only@*/ char * t)
{
free (q->t);
q->t = t;
return;
}
int
main (void)
{
/*@only@*/ char * l;
/*@only@*/ struct Q * q;
l = strdup ("");
q = Q_new (NULL);
Q_set (q, l);
free (l);
return EXIT_SUCCESS;
}
$ splint main.c
Splint 3.1.2 --- 21 Feb 2021
main.c: (in function Q_new)
main.c:15:3: Arrow access from possibly null pointer q: q->t
A possibly null pointer is dereferenced. Value is either the result of a
function which may return null (in which case, code should check it is not
null), or a global, parameter or structure field declared with the null
qualifier. (Use -nullderef to inhibit warning)
main.c:14:17: Storage q may become null
main.c: (in function main)
main.c:36:13: Null storage passed as non-null param: Q_new (NULL)
A possibly null pointer is passed as a parameter corresponding to a formal
parameter with no /*@null@*/ annotation. If NULL may be used for this
parameter, add a /*@null@*/ annotation to the function parameter declaration.
(Use -nullpass to inhibit warning)
main.c:39:8: Dead storage l passed as out parameter to free: l
Memory is used after it has been released (either by passing as an only param
or assigning to an only global). (Use -usereleased to inhibit warning)
main.c:38:12: Storage l released
main.c:41:22: Fresh storage q not released before return
A memory leak has been detected. Storage allocated locally is not released
before the last reference to it is lost. (Use -mustfreefresh to inhibit
warning)
main.c:36:2: Fresh storage q created
main.c:12:1: Function exported but not used outside main: Q_new
A declaration is exported, but not used outside this module. Declaration can
use static qualifier. (Use -exportlocal to inhibit warning)
main.c:17:1: Definition of Q_new
main.c:20:1: Function exported but not used outside main: Q_set
main.c:25:1: Definition of Q_set
Finished checking --- 6 code warnings
(The equivalent warning is main.c:39) |
|
| |
| ▲ | afdbcreid 2 hours ago | parent | prev | next [-] | | > I wonder if the certified compiler for safety critical uses has the same issue. It uses the same code, so yes. (Although I don't know what are their guidelines, it might be that they require avoiding code relying on implied bounds, for example). | |
| ▲ | high_na_euv 3 hours ago | parent | prev | next [-] | | which compiler? | | | |
| ▲ | wg0 2 hours ago | parent | prev [-] | | DeepSeek v4.1 Flash thinks it should NOT compile. Whereas in reality it DOES compile which is why it is filed as a bug. | | |
| ▲ | jug 2 hours ago | parent [-] | | They're seriously using AI as a judge for what to file? | | |
| ▲ | afdbcreid 2 hours ago | parent | next [-] | | The issue and none of the comments mention AI. It is pretty clear your parent said it by themselves. | |
| ▲ | wg0 2 hours ago | parent | prev [-] | | I was just checking what outcome an LLM would have based on the patterns in its probabilistic distribution it has seen the wild. Most LLMs would probably say this piece of code won't compile. | | |
| ▲ | ChickeNES 2 hours ago | parent [-] | | chatgpt and grok linked to the the soundness issue, claude I am in usage timeout, and gemini shit the bed as usual: "The compiler rejects the program with error[E0597] on the assignment q.0 = Some(&l)" |
|
|
|
|
|
| ▲ | Hugsbox 3 hours ago | parent | prev | next [-] |
| I don't understand how something like this could take so long to be discovered. Pretty crazy stuff. |
| |
| ▲ | lelanthran 2 hours ago | parent | next [-] | | > I don't understand how something like this could take so long to be discovered. Maybe they wrote it in C :-) On a serious note, old software is generally more trustworthy than new software, because bugs are discovered over time and with usage. | | |
| ▲ | zaphar 2 hours ago | parent [-] | | Old C software is generally more trustworthy than new C software. I don't think this rule of thumb transfers across languages very well. And the definition of new vs old has a fairly large effect. If a language has been under constant change it doesn't matter when it was started a large part of the codebase is "new". |
| |
| ▲ | fg137 2 hours ago | parent | prev [-] | | Because it's rarely used like this, just like weird bugs caused by edge cases found in all kinds of software in the world. |
|
|
| ▲ | fnord77 2 hours ago | parent | prev | next [-] |
| Here's the weakness of compiled programs. Does this compiled code have this vulnerability? You have no idea. At least with a VM or interpreter you can scan for vulnerable versions and replace the runtime or the specific library. With this you have to recompile everything |
| |
| ▲ | cowlevel an hour ago | parent | next [-] | | It's possible to scan compiled programs at the assembly or machine code level. Not enough people do, which is fair enough because it's a slog, but it makes all compiler UB transparent to the analysis. | |
| ▲ | baq an hour ago | parent | prev [-] | | That is less and less true by the day, for better or worse. |
|
|
| ▲ | badatnames 3 hours ago | parent | prev | next [-] |
| There is a collection of these someplace. Rust is better but it'll never be perfect, news at 10 |
| |
| ▲ | zer00eyz 2 hours ago | parent [-] | | Rust is good, I generally do not dislike it - but it does have flaws. I will happily continue to write things in Golang first. I don't enjoy refactors in Rust, and it's rare that I see things that genuinely need its raw performance. Cloudflare's Oxy is a stellar example of build in Golang till your design is settled and then port over for performance when you need it. |
|
|
| ▲ | z3ratul163071 an hour ago | parent | prev | next [-] |
| so now what? back to c++? |
| |
| ▲ | medler 36 minutes ago | parent [-] | | It seems the bug here was caught by Asan instead of at compile time, so basically, for this one bug, rust is reduced to C++-like behavior. You’re still better off using rust because of all the bugs the borrow checker does catch. The practical upshot to me is that you should be running your rust tests under asan. |
|
|
| ▲ | JABVOLT 2 hours ago | parent | prev | next [-] |
| very very good job |
|
| ▲ | rvz 3 hours ago | parent | prev | next [-] |
| This should not be a surprise at all given the amount of soundness bugs that were collected in the Rust compiler but no-one cared. [0] EDIT: I don’t even think HN cared either up until now. If you search this paper on HN, guess who posted it? Lets hope that this will be the only occurrence of soundness bugs in Rust and perhaps it needs a tiny disclaimer on claims of “safety guarantees”. [0] https://arxiv.org/abs/2608.28713 |
| |
| ▲ | optionalsquid 2 hours ago | parent | next [-] | | It looks like 18 of the 30 issues listed in table 4 had already been fixed when that paper was released, and there is activity in most of the rest. One was recently flagged as being fixed by -Znext-solver, and another has the submitter write that it is fixed, but the issue is not closed. And that's before you consider the impact of the individual issues; how many of the remaining issues impact "real" code? So I don't think it's fair to claim that "no-one cared". | |
| ▲ | purplesyringa 2 hours ago | parent | prev [-] | | I don't think "no one cared" is a fair characterisation. The paper doesn't support this conclusion, and from experience I'd say that the two difficulties in fixing unsoundness are doing so without breaking existing code (Rust guarantees stability unless the code is unsound, and introducing previously missing checks can cause sound code to stop compiling, which is a problem if it occurs often) and doing so in a reliable way that can be supported long-term. Rust is currently in the progress of stabilizing next-solver and Polonius, both of which fix multiple long-standing bugs and have been worked on for years now due to intrinsic complexity, performance considerations, compatibility issues, etc. It's not that no one cares, it's just that this stuff is hard and takes time. |
|
|
| ▲ | beanjuiceII 2 hours ago | parent | prev [-] |
| wonder what happened to this https://raphlinus.github.io/rust/2020/01/18/soundness-pledge... |
| |
| ▲ | jeremyjh 2 hours ago | parent | next [-] | | I think it has no relevance here at all. Actix was unsound because of prolific use of unsafe. That was a poor design decision but a conscious one. TFA is just a bug. Having ideals does not mean there are never bugs. | |
| ▲ | ModernMech 2 hours ago | parent | prev [-] | | What do you mean? |
|