---
title: "CWE-681: Incorrect Conversion between Numeric Types"
url: https://radicalnotion.ai/cwe/cwe-681
type: cwe
description: "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."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-681: Incorrect Conversion between Numeric Types

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 137
- **Of those, in CISA KEV:** 0
- **New in 2026:** 63
- **CWE catalog version:** 4.21

## Description

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.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Languages:** C (Undetermined), Python (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Other, Integrity | Unexpected State, Quality Degradation | 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. |

## Potential mitigations

### Implementation

Avoid making conversion between numeric types. Always check for the allowed ranges.

## Detection methods

### 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

## Demonstrative examples

### Example 1

In the following Java example, a float literal is cast to an integer, thus causing a loss of precision.

Bad code:

```java
int i = (int) 33457.8f;
```

### Example 2

This code adds a float and an integer together, casting the result to an integer.

Bad code:

```php
$floatVal = 1.8345;
$intVal = 3;
$result = (int)$floatVal + $intVal;
```

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.

### Example 3

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.

Bad code:

```c
unsigned int readdata () {
    int amount = 0;
    ...
    if (result == ERROR)
    amount = -1;
    ...
    return amount;
}
```

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.

### Example 4

In this example, depending on the return value of accessmainframe(), 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.

Bad code:

```c
unsigned int readdata () {
    int amount = 0;
    ...
    amount = accessmainframe();
    ...
    return amount;
}
```

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.

## Observed examples

| CVE | Description |
| --- | --- |
| 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. |

## Real CVEs with this weakness (sample of 12 of 137)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2016-0494 | Java SE, Java SE Embedded: 2D - takeover | critical | 10.0 | - | No | 2016-01-21 |
| CVE-2026-98288 | net: stmmac: fix TSO header length truncation | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2026-53053 | iommu/amd: Fix clone\_alias() to use the original device's devid | critical | 9.8 | - | No | 2026-06-24 |
| CVE-2022-40138 | - | critical | 9.8 | - | No | 2022-10-11 |
| CVE-2021-36357 | - | critical | 9.8 | - | No | 2021-10-22 |
| CVE-2021-38187 | Incorrect cast in anymap | critical | 9.8 | - | No | 2021-08-08 |
| CVE-2019-19317 | lookupName in resolve.c in SQLite 3.30.1 omits bits from the colUsed bitmask in the case of a generated column, which allows attackers to cause a denial of service or possibly have unspecified other impact. | critical | 9.8 | - | No | 2019-12-05 |
| CVE-2019-14842 | libnbd: remote code execution vulnerability | critical | 9.8 | - | No | 2019-11-26 |
| CVE-2016-3074 | php: Signedness vulnerability causing heap overflow in libgd | critical | 9.8 | - | No | 2016-04-26 |
| CVE-2022-36025 | Incorrect Conversion between Numeric Types in Besu Ethereum Client | critical | 9.1 | - | No | 2022-09-24 |
| CVE-2026-77412 | RabbitMQ amqp091-go: Denial of Service via Malicious Field Length in AMQP Client | high | 8.9 | - | No | 2026-09-16 |
| CVE-2026-89450 | iommu/tegra241-cmdqv: Reject a vSID wider than the SID\_MATCH field | high | 8.8 | - | No | 2026-09-11 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-704](https://radicalnotion.ai/cwe/cwe-704) | Incorrect Type Conversion or Cast |
| Child | [CWE-192](https://radicalnotion.ai/cwe/cwe-192) | Integer Coercion Error |
| Child | [CWE-194](https://radicalnotion.ai/cwe/cwe-194) | Unexpected Sign Extension |
| Child | [CWE-195](https://radicalnotion.ai/cwe/cwe-195) | Signed to Unsigned Conversion Error |
| Child | [CWE-196](https://radicalnotion.ai/cwe/cwe-196) | Unsigned to Signed Conversion Error |
| Child | [CWE-197](https://radicalnotion.ai/cwe/cwe-197) | Numeric Truncation Error |
| Can precede | [CWE-682](https://radicalnotion.ai/cwe/cwe-682) | Incorrect Calculation |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CERT C Secure Coding | Ensure that floating point conversions are within range of the new type | FLP34-C | CWE More Abstract |
| 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 |
| 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 | - |
| OpenSSF Secure Coding Guide for Python | Use an Appropriate Comparator for Numbers | pyscg-0006 | - |
| OpenSSF Secure Coding Guide for Python | Use String Literals for Decimal Construction | pyscg-0007 | - |

## Frequently asked questions

### 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?

137 recorded CVEs are attributed to CWE-681, including CVE-2016-0494, CVE-2026-98288 and CVE-2026-53053.

### 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?

137 recorded CVEs are caused by CWE-681; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/681.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-681). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
