CWE-704: Incorrect Type Conversion or Cast
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
The product does not correctly convert an object, resource, or structure from one type to a different type.
常见后果
影响范围: Other
技术影响: Other
检测方法
方法: 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.
有效性: High
观察示例
参考: 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)
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | - |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| CERT C Secure Coding | EXP05-C | Do not cast away a const qualification | - |
| CERT C Secure Coding | EXP39-C | Do not access a variable through a pointer of an incompatible type | CWE More Abstract |
| CERT C Secure Coding | INT31-C | Ensure that integer conversions do not result in lost or misinterpreted data | CWE More Abstract |
| CERT C Secure Coding | INT36-C | Converting a pointer to integer or integer to pointer | CWE More Abstract |
| CERT C Secure Coding | STR34-C | Cast characters to unsigned types before converting to larger integer sizes | CWE More Abstract |
| CERT C Secure Coding | STR37-C | Arguments to character handling functions must be representable as an unsigned char | CWE More Abstract |
| Software Fault Patterns | SFP1 | Glitch in computation | - |
| OMG ASCRM | ASCRM-CWE-704 | - |