Numeric Truncation Error |
Weakness ID: 197 (Weakness Base) | Status: Incomplete |
Description Summary
Extended Description
When a primitive is cast to a smaller primitive, the high order bits of the large value are lost in the conversion, potentially resulting in an unexpected value that is not equal to the original value. This value may be required as an index into a buffer, a loop iterator, or simply necessary state data. In any case, the value cannot be trusted and the system will be in an undefined state. While this method may be employed viably to isolate the low bits of a value, this usage is rare, and truncation usually implies that an implementation error has occurred.
Scope | Effect |
---|---|
Integrity | The true value of the data is lost and corrupted data is used. |
Example 1
This example, while not exploitable, shows the possible mangling of values associated with truncation errors:
The above code, when compiled and run, returns the following output: Int MAXINT: 2147483647 Short MAXINT: -1 A frequent paradigm for such a problem being exploitable is when the truncated value is used as an array index, which can happen implicitly when 64-bit values are used as indexes, as they are truncated to 32 bits.
Reference | Description |
---|---|
CVE-2009-0231 | Integer truncation of length value leads to heap-based buffer overflow. |
CVE-2008-3282 | Size of a particular type changes for 64-bit platforms, leading to an integer truncation in document processor causes incorrect index to be generated. |
Phase: Implementation Ensure that no casts, implicit or explicit, take place that move from a larger size primitive or a smaller size primitive. |
Nature | Type | ID | Name | View(s) this relationship pertains to |
---|---|---|---|---|
ChildOf | Weakness Base | 681 | Incorrect Conversion between Numeric Types | Development Concepts (primary)699 Research Concepts (primary)1000 |
ChildOf | Category | 738 | CERT C Secure Coding Section 04 - Integers (INT) | Weaknesses Addressed by the CERT C Secure Coding Standard (primary)734 |
CanAlsoBe | Category | 192 | Integer Coercion Error | Research Concepts1000 |
CanAlsoBe | Weakness Base | 194 | Unexpected Sign Extension | Research Concepts1000 |
CanAlsoBe | Weakness Variant | 195 | Signed to Unsigned Conversion Error | Research Concepts1000 |
CanAlsoBe | Weakness Variant | 196 | Unsigned to Signed Conversion Error | Research Concepts1000 |
This weakness has traditionally been under-studied and under-reported, although vulnerabilities in popular software have been published in 2008 and 2009. |
Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
---|---|---|---|
PLOVER | Numeric truncation error | ||
CLASP | Truncation error | ||
CERT C Secure Coding | INT02-C | Understand integer conversion rules | |
CERT C Secure Coding | INT05-C | Do not use input functions to convert character data if they cannot handle all possible inputs | |
CERT C Secure Coding | INT31-C | Ensure that integer conversions do not result in lost or misinterpreted data |
Submissions | ||||
---|---|---|---|---|
Submission Date | Submitter | Organization | Source | |
PLOVER | Externally Mined | |||
Modifications | ||||
Modification Date | Modifier | Organization | Source | |
2008-09-08 | CWE Content Team | MITRE | Internal | |
updated Applicable Platforms, Common Consequences, Relationships, Other Notes, Taxonomy Mappings | ||||
2008-11-24 | CWE Content Team | MITRE | Internal | |
updated Relationships, Taxonomy Mappings | ||||
2009-05-27 | CWE Content Team | MITRE | Internal | |
updated Demonstrative Examples | ||||
2009-07-27 | CWE Content Team | MITRE | Internal | |
updated Description, Observed Examples, Other Notes, Research Gaps |