---
title: "CWE-704: Incorrect Type Conversion or Cast"
url: https://radicalnotion.ai/cwe/cwe-704
type: cwe
description: "The product does not correctly convert an object, resource, or structure from one type to a different type."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-704: Incorrect Type Conversion or Cast

- **Abstraction:** Class
- **Structure:** Simple
- **Status:** Incomplete
- **CVEs with this as primary weakness:** 217
- **Of those, in CISA KEV:** 0
- **New in 2026:** 38
- **CWE catalog version:** 4.21

## Description

The product does not correctly convert an object, resource, or structure from one type to a different type.

## Modes of introduction

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

## Applicable platforms

**Languages:** C (Often), C++ (Often), Memory-Unsafe (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Other | Other | - |

## Detection methods

### Fuzzing

Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.

Effectiveness: High

## Demonstrative examples

### Example 1

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.

### Example 2

The following code uses a union to support the representation of different types of messages. It formats messages differently, depending on their type.

Bad code:

```c
#define NAME_TYPE 1
#define ID_TYPE 2

struct MessageBuffer
{
    int msgType;
    union {
        char *name;
        int nameID;
    };
};

int main (int argc, char **argv) {
    struct MessageBuffer buf;
    char *defaultMessage = "Hello World";

    buf.msgType = NAME_TYPE;
    buf.name = defaultMessage;
    printf("Pointer of buf.name is %p\n", buf.name);
    /* This particular value for nameID is used to make the code architecture-independent. If coming from untrusted input, it could be any value. */

    buf.nameID = (int)(defaultMessage + 1);
    printf("Pointer of buf.name is now %p\n", buf.name);
    if (buf.msgType == NAME_TYPE) {
        printf("Message: %s\n", buf.name);
    }
    else {
        printf("Message: Use ID %d\n", buf.nameID);
    }
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| 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-2022-3979 | Chain: data visualization program written in PHP uses the "!=" operator instead of the type-strict "!==" operator (CWE-480) when validating hash values, potentially leading to an incorrect type conversion (CWE-704) |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2015-3120 | flash-plugin: multiple code execution issues fixed in APSB15-16 | critical | 10.0 | - | No | 2015-07-09 |
| CVE-2026-58822 | Remote code execution in System | critical | 9.8 | - | No | 2026-09-08 |
| CVE-2026-15826 | User Profile Builder \<= 3.16.4 - Unauthenticated Authentication Bypass via Type Confusion to Administrator Account Takeover via 'username' Parameter | critical | 9.8 | - | No | 2026-08-15 |
| CVE-2025-39880 | libceph: fix invalid accesses to ceph\_connection\_v1\_info | critical | 9.8 | - | No | 2025-09-23 |
| CVE-2025-41648 | Pilz: Authentication Bypass in IndustrialPI Webstatus | critical | 9.8 | - | No | 2025-07-01 |
| CVE-2025-41646 | RevPi Webstatus application is vulnerable to an authentication bypass | critical | 9.8 | - | No | 2025-06-06 |
| CVE-2023-6249 | ipm: signed to unsigned conversion problem in esp32\_ipm\_send | critical | 9.8 | - | No | 2024-02-18 |
| CVE-2021-33318 | Improper Input Validation in IpMatcher | critical | 9.8 | - | No | 2022-05-16 |
| CVE-2019-25004 | Unsound casting in flatbuffers | critical | 9.8 | - | No | 2020-12-31 |
| CVE-2020-35880 | Unsoundness in bigint | critical | 9.8 | - | No | 2020-12-31 |
| CVE-2020-25576 | Unaligned memory access in rand\_core | critical | 9.8 | - | No | 2020-09-14 |
| CVE-2020-6151 | Accusoft ImageGear TIFF handle\_COMPRESSION\_PACKBITS memory corruption vulnerability | critical | 9.8 | - | No | 2020-09-01 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-1474](https://radicalnotion.ai/cwe/cwe-1474) | Non-Equivalent Data Transformation |
| Child | [CWE-588](https://radicalnotion.ai/cwe/cwe-588) | Attempt to Access Child of a Non-structure Pointer |
| Child | [CWE-681](https://radicalnotion.ai/cwe/cwe-681) | Incorrect Conversion between Numeric Types |
| Child | [CWE-843](https://radicalnotion.ai/cwe/cwe-843) | Access of Resource Using Incompatible Type |
| Child | [CWE-1389](https://radicalnotion.ai/cwe/cwe-1389) | Incorrect Parsing of Numbers with Different Radices |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CERT C Secure Coding | Do not cast away a const qualification | EXP05-C | - |
| CERT C Secure Coding | Do not access a variable through a pointer of an incompatible type | EXP39-C | CWE More Abstract |
| 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 | Converting a pointer to integer or integer to pointer | INT36-C | CWE More Abstract |
| CERT C Secure Coding | Cast characters to unsigned types before converting to larger integer sizes | STR34-C | CWE More Abstract |
| CERT C Secure Coding | Arguments to character handling functions must be representable as an unsigned char | STR37-C | CWE More Abstract |
| Software Fault Patterns | Glitch in computation | SFP1 | - |
| OMG ASCRM | - | ASCRM-CWE-704 | - |

## Frequently asked questions

### What is CWE-704?

The product does not correctly convert an object, resource, or structure from one type to a different type.

### What CVEs are caused by CWE-704?

217 recorded CVEs are attributed to CWE-704, including CVE-2015-3120, CVE-2026-58822 and CVE-2026-15826.

### How is CWE-704 detected?

Fuzzing: Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.

### What are the consequences of CWE-704?

Exploiting CWE-704 can lead to: Other.

### Is CWE-704 actively exploited?

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

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

---

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