---
title: "CWE-192: Integer Coercion Error"
url: https://radicalnotion.ai/cwe/cwe-192
type: cwe
description: "Integer coercion refers to a set of flaws pertaining to the type casting, extension, or truncation of primitive data types."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-192: Integer Coercion Error

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Incomplete
- **Likelihood of exploit:** Medium
- **CVEs with this as primary weakness:** 7
- **Of those, in CISA KEV:** 0
- **New in 2026:** 3
- **CWE catalog version:** 4.21

## Description

Integer coercion refers to a set of flaws pertaining to the type casting, extension, or truncation of primitive data types.

## Modes of introduction

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

## Applicable platforms

**Languages:** C (Undetermined), C++ (Undetermined), Java (Undetermined), C# (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability | DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Crash, Exit, or Restart | Integer coercion often leads to undefined states of execution resulting in infinite loops or crashes. |
| Integrity, Confidentiality, Availability | Execute Unauthorized Code or Commands | In some cases, integer coercion errors can lead to exploitable buffer overflow conditions, resulting in the execution of arbitrary code. |
| Integrity, Other | Other | Integer coercion errors result in an incorrect value being stored for the variable in question, or possible violating integrity of the data. |

## Potential mitigations

### Requirements

A language which throws exceptions on ambiguous data casts might be chosen.

### Architecture and Design

Design objects and program flow such that multiple or complex casts are unnecessary

### Implementation

Ensure that any data type casting that you must use is entirely understood in order to reduce the plausibility of error in use.

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

The following code is intended to read an incoming packet from a socket and extract one or more headers.

Bad code:

```c
DataPacket *packet;
int numHeaders;
PacketHeader *headers;

sock=AcceptSocketConnection();
ReadPacket(packet, sock);
numHeaders =packet->headers;

if (numHeaders > 100) {
    ExitError("too many headers!");
}
headers = malloc(numHeaders * sizeof(PacketHeader);
ParsePacketHeaders(packet, headers);
```

The code performs a check to make sure that the packet does not contain too many headers. However, numHeaders is defined as a signed int, so it could be negative. If the incoming packet specifies a value such as -3, then the malloc calculation will generate a negative number (say, -300 if each header can be a maximum of 100 bytes). When this result is provided to malloc(), it is first converted to a size\_t type. This conversion then produces a large value such as 4294966996, which may cause malloc() to fail or to allocate an extremely large amount of memory (CWE-195). With the appropriate negative numbers, an attacker could trick malloc() into using a very small positive number, which then allocates a buffer that is much smaller than expected, potentially leading to a buffer overflow.

### Example 2

The following code reads a maximum size and performs validation on that size. It then performs a strncpy, assuming it will not exceed the boundaries of the array. While the use of "short s" is forced in this particular example, short int's are frequently used within real-world code, such as code that processes structured data.

Bad code:

```c
int GetUntrustedInt () {
    return(0x0000FFFF);
}

void main (int argc, char **argv) {
    char path[256];
    char *input;
    int i;
    short s;
    unsigned int sz;

    i = GetUntrustedInt();
    s = i;
    /* s is -1 so it passes the safety check - CWE-697 */
    if (s > 256) {
        DiePainfully("go away!\n");
    }

    /* s is sign-extended and saved in sz */
    sz = s;

    /* output: i=65535, s=-1, sz=4294967295 - your mileage may vary */
    printf("i=%d, s=%d, sz=%u\n", i, s, sz);

    input = GetUserInput("Enter pathname:");

    /* strncpy interprets s as unsigned int, so it's treated as MAX_INT
    (CWE-195), enabling buffer overflow (CWE-119) */
    strncpy(path, input, s);
    path[255] = '\0'; /* don't want CWE-170 */
    printf("Path is: %s\n", path);
}
```

This code first exhibits an example of CWE-839, allowing "s" to be a negative number. When the negative short "s" is converted to an unsigned integer, it becomes an extremely large positive integer. When this converted integer is used by strncpy() it will lead to a buffer overflow (CWE-119).

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

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2022-2639 | kernel: openvswitch: integer underflow leads to out-of-bounds write in reserve\_sfa\_size() | high | 7.8 | - | No | 2022-09-01 |
| CVE-2014-125011 | FFmpeg ansi.c decode\_frame integer coercion | high | 7.8 | - | No | 2022-06-18 |
| CVE-2021-32996 | Integer Coercion Error in FANUC Robot Controllers | high | 7.5 | - | No | 2022-01-07 |
| CVE-2026-86143 | libxml2: libxml2: Data integrity issues due to integer overflow in write callbacks | high | 7.3 | - | No | 2026-09-05 |
| CVE-2026-8276 | bettercap MySQL Server mysql\_server.go integer coercion | medium | 6.3 | - | No | 2026-05-11 |
| CVE-2026-8275 | bettercap zerogod IPP Service zerogod\_ipp\_primitives.go ippReadChunkedBody integer coercion | medium | 6.3 | - | No | 2026-05-11 |
| CVE-2014-125012 | FFmpeg dxtroy.c integer coercion | medium | 5.5 | - | No | 2022-06-18 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-681](https://radicalnotion.ai/cwe/cwe-681) | Incorrect Conversion between Numeric Types |
| Related | [CWE-197](https://radicalnotion.ai/cwe/cwe-197) | Numeric Truncation Error |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CLASP | Integer coercion error | - | - |
| CERT C Secure Coding | Understand integer conversion rules | INT02-C | - |
| CERT C Secure Coding | Do not use input functions to convert character data if they cannot handle all possible inputs | INT05-C | - |
| CERT C Secure Coding | Ensure that integer conversions do not result in lost or misinterpreted data | INT31-C | Exact |

## Frequently asked questions

### What is CWE-192?

Integer coercion refers to a set of flaws pertaining to the type casting, extension, or truncation of primitive data types.

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

7 recorded CVEs are attributed to CWE-192, including CVE-2022-2639, CVE-2014-125011 and CVE-2021-32996.

### How do you prevent CWE-192?

A language which throws exceptions on ambiguous data casts might be chosen.

### How is CWE-192 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-192?

Exploiting CWE-192 can lead to: DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Crash, Exit, or Restart, Execute Unauthorized Code or Commands, Other.

### Is CWE-192 actively exploited?

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

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

---

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