Integer overflow or wraparound occurs when a calculation produces a numeric result that exceeds the maximum value a variable can hold. Instead of increasing as expected, the value wraps around to a very small or negative number, breaking the program's logic.

This vulnerability happens because computers store integers within fixed-size memory spaces. When an arithmetic operation like addition or multiplication exceeds this limit, the extra bits are discarded, causing the value to 'wrap around'—often to a minimum value or a negative number. For example, adding 1 to the maximum 32-bit integer doesn't create a larger number but flips it to a large negative value. Developers can prevent this by validating inputs before calculations, using safe math libraries, or choosing data types with larger capacity (like BigInteger in Java). Always assume user-provided or external data can trigger edge cases, and implement explicit checks for overflow conditions in critical operations like memory allocation, financial calculations, or loop counters.
Impact: DoS: Crash, Exit, or RestartDoS: Resource Consumption (Memory)DoS: Instability
This weakness can generally lead to undefined behavior and therefore crashes. When the calculated result is used for resource allocation, this weakness can cause too many (or too few) resources to be allocated, possibly enabling crashes if the product requests more resources than can be provided.
Impact: Modify Memory
If the value in question is important to data (as opposed to flow), simple data corruption has occurred. Also, if the overflow/wraparound 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 the product's implicit security policy.
Impact: Alter Execution LogicDoS: Crash, Exit, or RestartDoS: Resource Consumption (CPU)
If the overflow/wraparound occurs in a loop index variable, this could cause the loop to terminate at the wrong time - too early, too late, or not at all (i.e., infinite loops). With too many iterations, some loops could consume too many resources such as memory, file handles, etc., possibly leading to a crash or other DoS.
Impact: Bypass Protection Mechanism
If integer values are used in security-critical decisions, such as calculating quotas or allocation limits, integer overflows can be used to cause an incorrect security decision.
Strategy: Language Selection
Strategy: Libraries or Frameworks
Strategy: Input Validation
Strategy: Compilation or Build Hardening
cccc
// Variable for sales revenue for the quarter* float quarterRevenue = 0.0f;
cc
// Calculate quarterly total* long quarterSold = JanSold + FebSold + MarSold;
cMedium