CWE-681: Incorrect Conversion between Numeric Types
When converting from one data type to another, such as long to integer, data can be omitted or translated in a way that produces unexpected values. If the resulting values are used in a sensitive context, then dangerous behaviors may occur.
Last updated
Overview
CWE-681 (Incorrect Conversion between Numeric Types) is a base-level software weakness catalogued by MITRE in the Common Weakness Enumeration (CWE). It describes a recurring type of mistake that can lead to exploitable security vulnerabilities.
Real-world CVEs
107 recorded CVEs are caused by CWE-681 (Incorrect Conversion between Numeric Types). The highest-severity and most recent are shown first. 44 new CWE-681 CVEs have been recorded so far in 2026 (3 in 2025).
- CVE-2022-40138Critical · CVSS 9.8 · EPSS 69th2022-10-11
- CVE-2021-36357Critical · CVSS 9.8 · EPSS 68th2021-10-22
- CVE-2021-38187
Incorrect cast in anymap
Critical · CVSS 9.8 · EPSS 73th2021-08-08 - CVE-2019-19317Critical · CVSS 9.8 · EPSS 92th2019-12-05
- CVE-2019-14842Critical · CVSS 9.8 · EPSS 79th2019-11-26
- CVE-2016-3074Critical · CVSS 9.8 · EPSS 99th2016-04-26
- CVE-2022-36025
Incorrect Conversion between Numeric Types in Besu Ethereum Client
Critical · CVSS 9.1 · EPSS 65th2022-09-24 - CVE-2026-77412
RabbitMQ amqp091-go: Denial of Service via Malicious Field Length in AMQP Client
High · CVSS 8.9 · EPSS 45th2026-09-16 - CVE-2026-53053
iommu/amd: Fix clone_alias() to use the original device's devid
High · CVSS 8.8 · EPSS 3th2026-06-24 - CVE-2026-26178
Windows Advanced Rasterization Platform Elevation of Privilege Vulnerability
High · CVSS 8.8 · EPSS 36th2026-04-14 - CVE-2024-49093
Windows Resilient File System (ReFS) Elevation of Privilege Vulnerability
High · CVSS 8.8 · EPSS 61th2024-12-10 - CVE-2024-26162
Microsoft ODBC Driver Remote Code Execution Vulnerability
High · CVSS 8.8 · EPSS 81th2024-03-12
Showing 12 of 107 recorded CWE-681 CVEs. Get an alert for each new one, with AI-written analysis and fixes.
Monitor these CVEsCommon consequences
What can happen when CWE-681 is exploited.
Unexpected State, Quality Degradation
Affects: Other, Integrity
The program could wind up using the wrong number and generate incorrect results. If the number is used to allocate resources or make a security decision, then this could introduce a vulnerability.
How it happens
When it is introduced
Typically introduced during these phases of the software lifecycle.
Applies to
Languages
How to prevent it
Practical mitigations for CWE-681, grouped by where in the lifecycle they apply.
Avoid making conversion between numeric types. Always check for the allowed ranges.
How to detect it
Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Effectiveness: High
Code examples
MITRE examples of the weakness in code.
In the following Java example, a float literal is cast to an integer, thus causing a loss of precision.
Vulnerable example
int i = (int) 33457.8f;This code adds a float and an integer together, casting the result to an integer.
Normally, PHP will preserve the precision of this operation, making $result = 4.8345. After the cast to int, it is reasonable to expect PHP to follow rounding convention and set $result = 5. However, the explicit cast to int always rounds DOWN, so the final value of $result is 4. This behavior may have unintended consequences.
In this example the variable amount can hold a negative value when it is returned. Because the function is declared to return an unsigned int, amount will be implicitly converted to unsigned.
Vulnerable example
unsigned int readdata () {
int amount = 0;If the error condition in the code above is met, then the return value of readdata() will be 4,294,967,295 on a system that uses 32-bit integers.
In this example, depending on the return value of accecssmainframe(), the variable amount can hold a negative value when it is returned. Because the function is declared to return an unsigned value, amount will be implicitly cast to an unsigned number.
Vulnerable example
unsigned int readdata () {
int amount = 0;If the return value of accessmainframe() is -1, then the return value of readdata() will be 4,294,967,295 on a system that uses 32-bit integers.
Illustrative examples
Real CVEs that MITRE cites as examples of this weakness.
- CVE-2022-2639 — Chain: integer coercion error (CWE-192) prevents a return value from indicating an error, leading to out-of-bounds write (CWE-787)
- CVE-2021-43537 — Chain: in a web browser, an unsigned 64-bit integer is forcibly cast to a 32-bit integer (CWE-681) and potentially leading to an integer overflow (CWE-190). If an integer overflow occurs, this can cause heap memory corruption (CWE-122)
- CVE-2007-4268 — Chain: integer signedness error (CWE-195) passes signed comparison, leading to heap overflow (CWE-122)
- CVE-2007-4988 — Chain: signed short width value in image processor is sign extended during conversion to unsigned int, which leads to integer overflow and heap-based buffer overflow.
- 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.
Terminology & mappings
Mapped taxonomies
- CERT C Secure Coding: Ensure that floating point conversions are within range of the new type (FLP34-C) — CWE More Abstract fit
- CERT C Secure Coding: Use intmax_t or uintmax_t for formatted IO on programmer-defined integer types (INT15-C)
- CERT C Secure Coding: Ensure that integer conversions do not result in lost or misinterpreted data (INT31-C) — CWE More Abstract fit
- CERT C Secure Coding: Evaluate integer expressions in a larger size before comparing or assigning to that size (INT35-C)
- The CERT Oracle Secure Coding Standard for Java (2011): Ensure conversions of numeric types to narrower types do not result in lost or misinterpreted data (NUM12-J)
- Software Fault Patterns: Glitch in computation (SFP1)
- OMG ASCSM (ASCSM-CWE-681)
Frequently asked questions
Common questions about CWE-681.
- What is CWE-681?
- When converting from one data type to another, such as long to integer, data can be omitted or translated in a way that produces unexpected values. If the resulting values are used in a sensitive context, then dangerous behaviors may occur.
- What CVEs are caused by CWE-681?
- 107 recorded CVEs are attributed to CWE-681, including CVE-2022-40138, CVE-2021-36357 and CVE-2021-38187.
- How do you prevent CWE-681?
- Avoid making conversion between numeric types. Always check for the allowed ranges.
- How is CWE-681 detected?
- Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
- What are the consequences of CWE-681?
- Exploiting CWE-681 can lead to: Unexpected State, Quality Degradation.
- Is CWE-681 actively exploited?
- 107 recorded CVEs are caused by CWE-681; none are currently in CISA's KEV catalog of actively exploited flaws.
Sources
References
- MITRE CWE definition (CWE-681) (opens in a new tab)
- CWE-681 vulnerabilities on NVD (opens in a new tab)
- Learn: What is a CWE?
Weakness data is sourced from the MITRE CWE catalog (v4.20). CVE associations are aggregated and kept current by RadicalNotion.AI.
Track CWE-681 CVEs
Get an alert when a new CWE-681 CVE affects your products, with AI-written analysis and remediation steps.