logoalt Hacker News

dvtyesterday at 9:54 PM5 repliesview on HN

Obviously the way to prevent this is by bounds checking, which is literally in the `770594e` patch. It's just a bug and they happen routinely in all languages. Since this is doing pointer arithmetic, it could just as easily happen in unsafe Rust, for example.


Replies

gpmyesterday at 9:58 PM

Like they said, "no way to prevent this" (kind of bug from happening again).

show 1 reply
elliehyesterday at 10:54 PM

sure, but with unsafe Rust you have a very clear marking for the section of code that requires additional care and attention. it is also customary to include a "SAFETY" comment outlining why using unsafe is OK here

show 1 reply
amlutoyesterday at 10:45 PM

But one would have to explicitly choose to use unsafe Rust for this instead of ordinary safe Rust. And safe Rust has no particular difficulty writing to slots in an array or slice or vector specified by their index.

show 1 reply
Rygianyesterday at 10:24 PM

That's not prevention. That's remediation.