By default, a Rust project will panic on integer overflow in debug builds and will overflow on release builds. Two key points to note, however:
1. You can change the setting so that your project panics in release or overflows in debug mode.
2. We reserved the right to change the default at some point in the future. This will probably be widely communicated before it ever happens, and last I heard we are still waiting for the cost of performing those checks to be "reasonable" before thinking about making such a change.
What I don't understand is, checking for integer overflow is extremely cheap in hardware, so why is there any cost for performing those checks? What am I missing?
Because that's what processors do? (leaving aside backwards compatibility issues)
The whole point of higher level programming languages is to abstract away the fiddly bits of dealing with processors that we don't want to have to deal with.
This is one of those cases.
error: this arithmetic operation will overflow
--> src/main.rs:2:18
|
2 | let a: u64 = u64::MAX + 1;
| ^^^^^^^^^^^^ attempt to compute `u64::MAX + 1_u64`, which would overflow
|
= note: `#[deny(arithmetic_overflow)]` on by default
Rust also allows for overflowing arithmetic (preserving the default to fail):https://doc.rust-lang.org/std/?search=overflowing
It's generally less ergonomic, e.g.
let (zero, _did_overflow) = u64::MAX.overflowing_add(1);The correct answer is what shepmaster said in a sibling comment.
Here's a link to the runtime variant: https://play.rust-lang.org/?version=stable&mode=debug&editio...
As a sibling notes, currently, this is for debug builds. So, if you change that playground to "Release", you'll see it wrap.
(I love this feature, and I wish they had done it in release mode too. The sibling comment has some notes on that, too.)
(But, e.g., were `git` written in Rust, presumably the end product would be a release build. Now, you can enable the check there, but that is something you have to do, today.)
(But also note, that, in all cases, it's well-defined. Vs. C, where some overflows are UB.)
Unfortunately, there is a circular dependency here. Languages are reluctant to make integer overflows error conditions because there is a moderately high overhead to checking overflow conditions constantly, and processors (and compilers) are unwilling to make overflow checks cheaper because they benchmarks they care about don't do such checks.
Also a surprising amount of undefined behavior gets relied on in code. I don't use Rust, but the idea that they could potentially change the future behavior on overflow seems... risky?
This crashes in Swift
var potentialOverflow = Int16.max
potentialOverflow += 1
This does not crash var potentialOverflow = Int16.max
potentialOverflow &+= 1
[1] https://docs.swift.org/swift-book/LanguageGuide/AdvancedOper...I think it makes a lot of sense to think about. Ultimately, it matters more in some applications than in others.
From the language side, what I wish for is a sort of NaN for integer operations. I would not want to check for overflow on every operation, but I would want to know after a couple of them if somewhere an overflow had occurred. On the hardware side this could be done with a sticky overflow bit, which some architectures already support.
I think the ball is on the hardware side and in my opinion Rust did the most sensible thing possible with contemporary hardware.
That's simply not true and has wide-reaching horrible effects that can occur. The wrong number of tickets can be purchased from a website, charging for less than were purchased. The DNR order can be put in place instead of SAVE LIFE. There are countless security issues that can occur.
Saying that integer overflow is only an issue for memory safety is really bad and incorrect advice.
`UserAccessLevel > Threshold`
Like there could be a million ways an integer becoming small could mess up something.
Also there are business logic issues as well
Don't see how. Given the hardware Rust is designed to program you have to compromise some or all of efficiency, memory usage and complexity to solve overflow.
The cost of operating on 64-bit integers is about the same as operating on 32-bit integers on most modern CPUs (except maybe 32-bit cores in MCUs).
To install the latest git on Ubuntu:
sudo apt upgrade git
[Former post included instructions on how to install git from https://launchpad.net/~git-core/+archive/ubuntu/ppa]Note that I said Ubuntu's git package was updated, but didn't say to what version. Ubuntu like most stable distributions cherry-pick security fixes rather than bump major versions, so Ubuntu users will get a version with these vulnerabilities patched but not necessarily a bump up to 2.39.1. See https://ubuntu.com/security/notices/USN-5810-1 for details.
The updater just gave me 1:2.37.2-1ubuntu1.2 (to replace 1:2.37.2-1ubuntu1.1). It said it addresses the two CVEs in question.
So they (Ubuntu or maybe Debian) are taking the approach of patching a slightly older git version.
I can't find anything in the Debian changelogs referring to the CVEs. Yet the Ubuntu changelog refers to it as a debian patch...
Anyone know anything about Debian?
Overall fixing this it looks like routine house keeping and nothing major.
> It may also be triggered indirectly via Git’s export-subst mechanism, which applies the formatting modifiers to selected files when using git archive.
This very practical to exploit on Git forges like GitHub or GitLab which allow their users to download archives of tags or branches.
huh, I would have thought for sure they would have linked to git/git from which that repo was forked
Also, the 2.39.1 tag alleges it was created Dec 13th - I wonder why they held it so long? I would have thought maybe embargo but the actual commit says "security fix" https://github.com/git/git/commit/01443f01b7c6a3c6ef03268b64...
edit: just because someone puts up an "easy" ""free"" service, does not mean they are kind. GitHub is not your friend for git issues. I woul dhope this site would support true FOSS
If you don't believe me, have a look, this was probably submitted too, and is languishing somewhere off the front page while this one is at the top, by virtue of people voting for it and not the other.
`brew install git`
The latest version in Ventura 13.1 seems to be either 2.24.3 or 2.37.1 (not all my co-workers machines match). I'm not sure if these are defaults, different because some of us have XCode, or if some of us manually installed. In any case, brew install got me up to date.
reads new git security threat
"brew upgrade"
done!
The vulnerability is Windows-only, so maybe whatever Windows users do to install git always gives them git-gui. But at least for Linux, the distro might package it separately (mine does), so you won't even have it if you didn't install it.
echo "calc.exe" > aspell.cmd
git commit -a -m"lolol windows"
and wait for someone to clone that repoI have upgraded my brew install, but am unsure of what to do with the vulnerable system install.
Some vendors use the term Security Bulletins