Int. overflow: what is it?

Print anything with Printful



Integer overflow occurs when a computer data type’s sign changes as it reaches the end of its range. This can cause memory errors and overflows, which can be exploited by hackers. Mitigation includes using larger data types or incremental counters.

Integer overflow refers to the phenomenon that occurs in some types of computer data in which their signs change from positive to negative, or vice versa, as they reach the ends of their applicable ranges. In computer ranges, integer data types have circular ranges and when they reach one end of the range, they immediately move to the other end of the range. This is also called integer overflow.

A signed integer can contain a range of values ​​from -231 to (231) – 1. This integer cannot have a value of (-231) – 1; rather, the next number it increases to is at the other end of its range: (231 – 1). The change from negative to positive at the end of its range is an example of an integer overflow. Similarly, an integer cannot have a value of 231; instead, this value would transition to the other end of its range and become -231.

This overflow has significant consequences when programming. An array can contain only as many indices as the integer type allows, and negative indices don’t matter. If a programmer tries to create an array larger than the integer type allows, significant memory errors can occur because integer overflow would result in a negative index. This is especially dangerous in languages ​​that don’t have explicit bounds checking for arrays, such as C++.

When an integer overflow occurs, related types of overflows such as buffer overflow, heap overflow, and stack buffer overflow can occur. In all of these cases, integer overflow acts to overwhelm memory structures with more data than those structures can conceivably hold. These overflows, in simple programs, often do little more than cause an invalid read or write error. Hackers’ manipulation of this issue, however, can engineer memory errors that can cause more serious problems.

In most simple programs, integer overflow isn’t a big deal. The bounds of the integer type are large enough that the overflow problem doesn’t kick in unless you’re handling a lot of data at the same time. In some cases the overflow can be mitigated, such as with incremental counters, by using a larger data type with a larger range. The larger data type could, in theory, encounter the same overflow problem, but as ranges of data types get larger, the chances of doing so decrease. The range of each integer data type is at least twice the size of the next smallest one, so there is ample room for additional data.




Protect your devices with Threat Protection by NordVPN


Skip to content