"The first principle was security: The principle that every syntactically incorrect program should be rejected by the compiler and that every syntactically correct program should give a result or an error message that was predictable and comprehensible in terms of the source language program itself. Thus no core dumps should ever be necessary. It was logically impossible for any source language program to cause the computer to run wild, either at compile time or at run time. 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 pre- cautions would have long been against the law."
https://www.cs.fsu.edu/~engelen/courses/COP4610/hoare.pdf
I guess in IT one needs a couple of decades to be proven right.
Feel free to start rewriting libpng and freetype in rust. See you in 25 years?
We are stuck with C due to the synergy effects of having a free beer OS with source code available.
And the common sense at the time did not put too much focus on memory safety.
Modula-2 and Pascal compilers had the necessary switches to make the languages just as unsafe as C, and anything related to ultimate performance out of 8086 and 68000 required Assembly anyway.
Png is a pretty simple format that everyone already implements. Would you rather use something ad-hoc?
Since the access to the buffer happens inside libpng, this means libpng should have bounds checks compiled in according to your argument. (Hoping that the compiler can elide them by seeing through the library interface is but wishful thinking.)
Would you rather have a slower version of libpng that defends against screwups of the calling code, or a faster version that assumes the calling code is sane? Not an obvious choice to me.
"A vulnerability exists in the function `Load_SBit_Png`, which processes PNG images embedded into fonts. This function:
1) Obtains the image width and height from the header as 32-bit integers.
2) Truncates the obtained values to 16 bit and stores them in a `TT_SBit_Metrics` structure.
3) Uses the truncated values to calculate the bitmap size.
4) Allocates the backing store of that size.
5) Passes `png_struct` and the backing store to a libpng function.
The issue is that libpng uses the original 32-bit values, which are saved in `png_struct`. Therefore, if the original width and/or height are greater than 65535, the allocated buffer won't be able to fit the bitmap."
This one could only happen in an memory unsafe programming language. Having bounds checks on the destination buffer would have avoided the problem.