Integer underflow occurs when a subtraction operation results in a value smaller than the data type's minimum limit, causing the value to wrap around to a large, incorrect number.
Integer underflow, also known as wraparound, happens when a program subtracts a larger number from a smaller one, pushing the result below the minimum value the integer type can hold. Instead of throwing an error, the value wraps around to the maximum end of the range—for example, an unsigned 8-bit integer going from 0 to 255 after subtracting 1. This creates a logic flaw where the program operates on a wildly incorrect value, often leading to unexpected behavior. This vulnerability affects both signed and unsigned integers and is a common source of critical security flaws. In signed integers, underflow can flip a positive value to a massive negative one, while in unsigned integers, it creates an unexpectedly large positive value. Developers must validate all subtraction inputs, use safe math libraries, or choose data types with sufficient range to prevent these dangerous wrap-around scenarios.
Impact: DoS: Crash, Exit, or RestartDoS: Resource Consumption (CPU)DoS: Resource Consumption (Memory)DoS: Instability
This weakness will generally lead to undefined behavior and therefore crashes. In the case of overflows involving loop index variables, the likelihood of infinite loops is also high.
Impact: Modify Memory
If the value in question is important to data (as opposed to flow), simple data corruption has occurred. Also, if the wrap around results in other conditions such as buffer overflows, further memory corruption may occur.
Impact: Execute Unauthorized Code or CommandsBypass Protection Mechanism
This weakness can sometimes trigger buffer overflows which can be used to execute arbitrary code. This is usually outside the scope of a program's implicit security policy.
cc