TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Retrofitting spatial safety to lines of C++

84 pointsby jandeboevrie6 months ago

11 comments

titzer6 months ago
&gt; We’ve begun by enabling hardened libc++, which adds bounds checking to standard C++ data structures, eliminating a significant class of spatial safety bugs.<p>Well, it&#x27;s 2024 and remember arguing this 20+ years ago. Programs have bugs that bounds checking catches. And making it a language built-in exposes it to compiler optimizations specifically targeting bounds checks, eliminating many and bringing the dynamic cost down immensely. Just turning them on in libraries doesn&#x27;t necessarily expose all the compiler optimizations, but it&#x27;s a start. Safety checks should really be built into the language.
评论 #42155396 未加载
评论 #42156322 未加载
WalterBright6 months ago
Dlang added array bounds checking 20 years ago. It&#x27;s a huge win. As evidenced by the article noting that 40% of the memory safety bugs were spacial.<p>I used to have all kinds of problems with array overflows. I didn&#x27;t make them very often, but when I did, they took a long time to track down. They&#x27;ve been gone for 20 years now.<p>Note that it would be easy to add it to C&#x2F;C++:<p><a href="https:&#x2F;&#x2F;www.digitalmars.com&#x2F;articles&#x2F;C-biggest-mistake.html" rel="nofollow">https:&#x2F;&#x2F;www.digitalmars.com&#x2F;articles&#x2F;C-biggest-mistake.html</a><p>It would be the most <i>useful</i> and cost-effective enhancement ever.
评论 #42155331 未加载
评论 #42155314 未加载
vblanco6 months ago
Game developers have been doing this since forever, its one of their main reasons to avoid the STL.<p>EASTL has this as a feature by default, and unreal engine container library has the boundchecks enabled on most games. The performance cost of those boundchecks in practice is well worth the reduction of bugs even on performance sensitive code.
评论 #42158051 未加载
omoikane6 months ago
&gt; Hardening libc++ resulted in an average 0.30% performance impact<p>Maybe what really happened is that compiler technology has improved such that they are able to remove most redundant checks, such that it only costs 0.30% today. I can imagine things going the opposite direction 20 years ago, as in &quot;we removed some bounds checks and gained X% of performance&quot;.
评论 #42155109 未加载
评论 #42156217 未加载
评论 #42155503 未加载
alserio6 months ago
&gt; We first enabled hardened libc++ in our tests over a year ago. This allowed us to identify and fix hundreds of previously undetected bugs in our code and tests.<p>That&#x27;s something
dzogchen6 months ago
To “lines of C++” and to “hundreds of millions of lines of C++” is quite a different title.
TinkersW6 months ago
I wonder if google really never had this turned on before? Like this has been available in the C++ standard library for decades(normally as a debug feature to catch errors in development, but some implementations such as MS support it in release also).<p>Might explain why they claimed 70% of exploits were memory related..
评论 #42157367 未加载
DLoupe6 months ago
&gt; The safety checks have uncovered over 1,000 bugs<p>In most implementations of the standard library, safety checks can be enabled with a simple #define. In some, it&#x27;s the default behavior in DEBUG mode. I wonder what this library improves on that and why these bugs have not been discovered before.
评论 #42155401 未加载
评论 #42155332 未加载
评论 #42155538 未加载
dataflow6 months ago
PSA: Perhaps this is stating the obvious, but if you want bounds checking in your own code, start replacing T* with std::span&lt;T&gt; or std::span&lt;T&gt;::iterator whenever the target is an array.
评论 #42155146 未加载
Animats6 months ago
New buzzword for old thing alert.
评论 #42153130 未加载
评论 #42153239 未加载
评论 #42153223 未加载
评论 #42151720 未加载
andrewstuart6 months ago
&gt;&gt; spatial safety vulnerabilities represent 40% of in-the-wild memory safety exploits<p>Rust advocates tend to turn stats like this into “40% of all security issues are memory safety”, which sounds very similar but is false.
评论 #42153518 未加载
评论 #42155044 未加载
评论 #42155436 未加载