---
title: "CWE-194: Unexpected Sign Extension"
url: https://radicalnotion.ai/cwe/cwe-194
type: cwe
description: "The product performs an operation on a number that causes it to be sign extended when it is transformed into a larger data type."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-194: Unexpected Sign Extension

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

## Description

The product performs an operation on a number that causes it to be sign extended when it is transformed into a larger data type.

## Modes of introduction

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

## Applicable platforms

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

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Confidentiality, Availability, Other | Read Memory, Modify Memory, Other | When an unexpected sign extension occurs in code that operates directly on memory buffers, such as a size value or a memory index, then it could cause the program to write or read outside the boundaries of the intended buffer. If the numeric value is associated with an application-level resource, such as a quantity or price for a product in an e-commerce site, then the sign extension could produce a value that is much higher (or lower) than the application's allowable range. When the original number is negative, this can produce unexpected values that lead to resultant weaknesses. |

## Potential mitigations

### Implementation

Avoid using signed variables if you don't need to represent negative values. When negative values are needed, perform validation after you save those values to larger data types, or before passing them to functions that are expecting unsigned values.

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

## Demonstrative examples

### Example 1

The following code reads a maximum size and performs a sanity check 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-2018-10887 | Chain: unexpected sign extension (CWE-194) leads to integer overflow (CWE-190), causing an out-of-bounds read (CWE-125) |
| CVE-1999-0234 | Sign extension error produces -1 value that is treated as a command separator, enabling OS command injection. |
| CVE-2003-0161 | Product uses "char" type for input character. When char is implemented as a signed type, ASCII value 0xFF (255), a sign extension produces a -1 value that is treated as a program-specific separator value, effectively disabling a length check and leading to a buffer overflow. This is also a multiple interpretation error. |
| 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-2006-1834 | Chain: signedness error allows bypass of a length check; later sign extension makes exploitation easier. |
| CVE-2005-2753 | Sign extension when manipulating Pascal-style strings leads to integer overflow and improper memory copy. |

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2022-32138 | CODESYS runtime system prone to denial of service due to Unexpected Sign Extension | high | 8.8 | - | No | 2022-06-24 |
| CVE-2018-10887 | libgit2: integer overflow leads to out-of-bounds read in git\_delta\_apply, allowing to read before base array | high | 8.1 | - | No | 2018-07-10 |
| CVE-2021-38434 | FATEK Automation WinProladder | high | 7.8 | - | No | 2021-10-18 |
| CVE-2020-13544 | SoftMaker Office TextMaker Document Record 0x001f sign-extension vulnerability | high | 7.8 | - | No | 2021-01-06 |
| CVE-2025-13632 | Inappropriate implementation in DevTools | medium | 5.4 | - | No | 2025-12-02 |

## 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 | Sign extension error | - | - |
| Software Fault Patterns | Glitch in computation | SFP1 | - |
| CERT C Secure Coding | Ensure that integer conversions do not result in lost or misinterpreted data | INT31-C | CWE More Specific |

## Frequently asked questions

### What is CWE-194?

The product performs an operation on a number that causes it to be sign extended when it is transformed into a larger data type.

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

5 recorded CVEs are attributed to CWE-194, including CVE-2022-32138, CVE-2018-10887 and CVE-2021-38434.

### How do you prevent CWE-194?

Avoid using signed variables if you don't need to represent negative values. When negative values are needed, perform validation after you save those values to larger data types, or before passing them to functions that are expecting unsigned values.

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

Exploiting CWE-194 can lead to: Read Memory, Modify Memory, Other.

### Is CWE-194 actively exploited?

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

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

---

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