CWE-191: Integer Underflow (Wrap or Wraparound)
The product subtracts one value from another, such that the result is less than the minimum allowable integer value, which produces a value that is not equal to the correct result.
View on MITREExtended Description
This can happen in signed and unsigned cases.
Technical Details
- Structure
- Simple
Applicable To
Security Consequences
Scope
Impact
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.
Scope
Impact
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.
Scope
Impact
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.
Mitigation Strategies
No mitigation information available for this CWE.
Detection Methods
No detection method information available for this CWE.
Code Examples & CVEs
Demonstrative Examples
The following example subtracts from a 32 bit signed integer.
The example has an integer underflow. The value of i is already at the lowest negative value possible, so after subtracting 1, the new value of i is 2147483647.
This code performs a stack allocation based on a length calculation.
Since a and b are declared as signed ints, the "a - b" subtraction gives a negative result (-1). However, since len is declared to be unsigned, len is cast to an extremely large positive number (on 32-bit systems - 4294967295). As a result, the buffer buf[len] declaration uses an extremely large size to allocate on the stack, very likely more than the entire computer's memory space.
Observed CVE Examples (4)
CWE Relationships
No relationship information available for this CWE.
Frequently Asked Questions
What is CWE-191: Integer Underflow (Wrap or Wraparound)?+
CWE-191: Integer Underflow (Wrap or Wraparound) is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product subtracts one value from another, such that the result is less than the minimum allowable integer value, which produces a value that is not equal to the correct result. This can happen in signed and unsigned cases.
What are the security consequences of Integer Underflow (Wrap or Wraparound)?+
If exploited, CWE-191 (Integer Underflow (Wrap or Wraparound)) it can compromise Availability, Integrity, Confidentiality and Access Control, leading to outcomes such as DoS: Crash, Exit, or Restart, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Instability, Modify Memory and Execute Unauthorized Code or Commands.
Which programming languages are affected by Integer Underflow (Wrap or Wraparound)?+
CWE-191 commonly affects C, C++, Java and C#. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
What are real-world examples of Integer Underflow (Wrap or Wraparound)?+
MITRE documents real CVEs mapped to CWE-191, including CVE-2004-0816, CVE-2004-1002, CVE-2005-0199 and CVE-2005-1891. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.
What is the difference between a CWE and a CVE?+
A CWE (Common Weakness Enumeration) like CWE-191 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.