Remix.run Logo
▲ seeknotfind a day ago

Yes, this is the best answer. This also works with `-fsanitize=unsigned-integer-overflow`.

▲Matheus28 a day ago | parent [-]

Unsigned integer overflow is well defined, though. Not something that should be sanitized. A lot of code out there relies on it.

▲seeknotfind 17 hours ago | parent [-]

Ubsan is a misnomer here from a technical perspective. However overflow unsigned or not is unexpected in many cases. As such, sanitizing it (and many other hard to reason about behaviors) by default is great practice. For an example, when unsigned values are used to count, overflows from summing over 2**N often result in incorrect behavior. This may be incrementing or even counting beans.

One particularly famous example of a bug: https://projectzero.google/2023/01/exploiting-null-dereferen...

We usually get away with ignoring unsigned rollover because most application counts don't exceed 2**32 or 2**64. However, many can exceed these values, and in those cases, explicitly handling this case in critical systems is often better than ignoring potentially erroneous behavior.

Another concern, some people might have about this is the performance implications or what to do when you want to allow overflow. In that case you can locally disable overflow protections.