By adding length counts and explicit bounds checks locally you provide local reasoning to back up this non-local reasoning which is much *easier* to make and maintain correct. I think that would result in code that is less likely to have similar bugs in the future.
If you read what they proposed and disagreed with it, then don't ask "What do you propose?" - Argue/debate why you think their proposal, which you read, is not useful.
Because otherwise you make people learn 100 other things at once to start using it effectively, and then they don't.
The advantage of Rust is that you can produce efficient safe code. The disadvantage is that you have to learn a different language first, which deters adoption.
Does Zig fill this space in any way? It still allows manual memory management but offers more protections, the specifics I'm unclear on.
I'd argue the constant stream of CVEs due to memory unsafety is even more tiresome.
If this is a common function in the webp library, this function is probably called something like a trillion times a day.
I also wouldn't be surprised if patching, rebuilding and distributing this fixed version of libwebp to all of these devices would be comparable to the extra cost of decoding.
Your intuition about the cost of a patch vs the extra instructions in the hot path to check bounds everywhere is also very much wrong: the cost of a patch (which is also amortized among many fixes) is not even close. The hot path adds up when you call it a lot.
That's the whole point of webp, though.
WebP gets a slight pass because the code is so old; WebP is at least partly based on code from On2 that extends back at least until the early '00s. Rewriting working code is always going to be lower priority than writing new code (and it's not always a safety win either; being deployed for 10 years gets you an awful lot of real-world testing!).
But look at implementations for newer image formats and you see more of the same; C and C++ with the token java implementation that won't get used outside of the JVM.
Maybe WEBP should have been written in Assembly, all the speed and I bet quite safe. /s
https://llvm.org/devmtg/2023-05/slides/TechnicalTalks-May11/...
My favourite quote, C.A.R Hoare's "The 1980 ACM Turing Award Lecture"
"A consequence of this principle is that every occurrence of every subscript of every subscripted variable was on every occasion checked at run time against both the upper and the lower declared bounds of the array. Many years later we asked our customers whether they wished us to provide an option to switch off these checks in the interests of efficiency on production runs. Unanimously, they urged us not to--they already knew how frequently subscript errors occur on production runs where failure to detect them could be disastrous. I note with fear and horror that even in 1980 language designers and users have not learned this lesson. In any respectable branch of engineering, failure to observe such elementary precautions would have long been against the law."
-- https://www.labouseur.com/projects/codeReckon/papers/The-Emp...
(Discussed in https://news.ycombinator.com/item?id=37600852)