---
title: "CWE-197: Numeric Truncation Error"
url: https://radicalnotion.ai/cwe/cwe-197
type: cwe
description: "Truncation errors occur when a primitive is cast to a primitive of a smaller size and data is lost in the conversion."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-197: Numeric Truncation Error

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Incomplete
- **Likelihood of exploit:** Low
- **CVEs with this as primary weakness:** 97
- **Of those, in CISA KEV:** 1
- **New in 2026:** 61
- **CWE catalog version:** 4.21

## Description

Truncation errors occur when a primitive is cast to a primitive of a smaller size and data is lost in the conversion.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | While truncation may be employed viably to isolate the low bits of a value, this usage is rare, and truncation usually implies that an implementation error has occurred. |

## Applicable platforms

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

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity | Modify Memory, Varies by Context | When a primitive is cast to a smaller primitive, the high order bits of the large value are lost in the conversion, potentially resulting in an unexpected value that is not equal to the original value. This value may be required as an index into a buffer, a loop iterator, or simply necessary state data. In any case, the value cannot be trusted and the system will be in an undefined state. |

## Potential mitigations

### Implementation

Ensure that no casts, implicit or explicit, take place that move from a larger size primitive or a smaller size primitive.

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

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

This example, while not exploitable, shows the possible mangling of values associated with truncation errors:

Bad code:

```c
int intPrimitive;
short shortPrimitive;
intPrimitive = (int)(~((int)0) ^ (1 << (sizeof(int)*8-1)));
shortPrimitive = intPrimitive;
printf("Int MAXINT: %d\nShort MAXINT: %d\n", intPrimitive, shortPrimitive);
```

Result code:

```
Int MAXINT: 2147483647
Short MAXINT: -1
```

### Example 2

In the following Java example, the method updateSalesForProduct is part of a business application class that updates the sales information for a particular product. The method receives as arguments the product ID and the integer amount sold. The product ID is used to retrieve the total product count from an inventory object which returns the count as an integer. Before calling the method of the sales object to update the sales count the integer values are converted to The primitive type short since the method requires short type for the method arguments.

Bad code:

```java
...
// update sales database for number of product sold with product ID
public void updateSalesForProduct(String productID, int amountSold) {

    // get the total number of products in inventory database
    int productCount = inventory.getProductCount(productID);
    // convert integer values to short, the method for the

    // sales object requires the parameters to be of type short
    short count = (short) productCount;
    short sold = (short) amountSold;
    // update sales database for product
    sales.updateSalesCount(productID, count, sold);
}
...
```

Good code:

```java
...
// update sales database for number of product sold with product ID
public void updateSalesForProduct(String productID, int amountSold) {

    // get the total number of products in inventory database
    int productCount = inventory.getProductCount(productID);
    // make sure that integer numbers are not greater than

    // maximum value for type short before converting
    if ((productCount < Short.MAX_VALUE) && (amountSold < Short.MAX_VALUE)) {

        // convert integer values to short, the method for the

        // sales object requires the parameters to be of type short
        short count = (short) productCount;
        short sold = (short) amountSold;
        // update sales database for product
        sales.updateSalesCount(productID, count, sold);

    else {
    // throw exception or perform other processing
        ...
    }
}
...
```

However, a numeric truncation error can occur if the integer values are higher than the maximum value allowed for the primitive type short. This can cause unexpected results or loss or corruption of data. In this case the sales database may be corrupted with incorrect data. Explicit casting from a larger size primitive type to a smaller size primitive type should be prevented. The following example an if statement is added to validate that the integer values less than the maximum value for the primitive type short before the explicit cast and the call to the sales method.

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2020-17087 | Chain: integer truncation (CWE-197) causes small buffer allocation (CWE-131) leading to out-of-bounds write (CWE-787) in kernel pool, as exploited in the wild per CISA KEV. |
| 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 97)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2022-42475 | Fortinet FortiOS Heap-Based Buffer Overflow Vulnerability | critical | 10.0 | - | Yes | 2023-01-02 |
| CVE-2026-115889 | Wasmtime: Bit-packing in Cranelift compiler causes silent overflow and miscompilation | critical | 9.9 | - | No | 2026-10-23 |
| CVE-2024-43639 | Windows KDC Proxy Remote Code Execution Vulnerability | critical | 9.8 | - | No | 2024-11-12 |
| CVE-2026-126254 | - | critical | 9.6 | - | No | 2026-11-11 |
| CVE-2026-87529 | Numeric truncation error in Media | critical | 9.6 | - | No | 2026-09-09 |
| CVE-2026-109588 | Numeric truncation in the MPU buffer authorization check in FreeRTOS-Kernel | critical | 9.3 | - | No | 2026-10-16 |
| CVE-2026-136156 | Valkey: Integer truncation in cluster publish message construction causes a heap buffer overflow | high | 8.8 | - | No | 2026-11-24 |
| CVE-2026-111308 | Microsoft Office Word Remote Code Execution Vulnerability | high | 8.8 | - | No | 2026-11-10 |
| CVE-2026-108451 | Microsoft Office Word Remote Code Execution Vulnerability | high | 8.8 | - | No | 2026-10-15 |
| CVE-2026-78512 | Microsoft Office Word Remote Code Execution Vulnerability | high | 8.8 | - | No | 2026-09-08 |
| CVE-2024-49018 | SQL Server Native Client Remote Code Execution Vulnerability | high | 8.8 | - | No | 2024-11-12 |
| CVE-2024-43519 | Microsoft WDAC OLE DB provider for SQL Server Remote Code Execution Vulnerability | high | 8.8 | - | No | 2024-10-08 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-681](https://radicalnotion.ai/cwe/cwe-681) | Incorrect Conversion between Numeric Types |
| Can also be | [CWE-192](https://radicalnotion.ai/cwe/cwe-192) | Integer Coercion Error |
| Can also be | [CWE-194](https://radicalnotion.ai/cwe/cwe-194) | Unexpected Sign Extension |
| Can also be | [CWE-195](https://radicalnotion.ai/cwe/cwe-195) | Signed to Unsigned Conversion Error |
| Can also be | [CWE-196](https://radicalnotion.ai/cwe/cwe-196) | Unsigned to Signed Conversion Error |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Numeric truncation error | - | - |
| CLASP | Truncation error | - | - |
| CERT C Secure Coding | Distinguish between characters read from a file and EOF or WEOF | FIO34-C | CWE More Abstract |
| 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 | 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 | CWE More Abstract |
| 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 | - |
| OpenSSF Secure Coding Guide for Python | Use Integer Loop Counters | pyscg-0004 | - |
| OpenSSF Secure Coding Guide for Python | Specify Rounding for Numeric Conversions | pyscg-0005 | - |

## Frequently asked questions

### What is CWE-197?

Truncation errors occur when a primitive is cast to a primitive of a smaller size and data is lost in the conversion.

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

97 recorded CVEs are attributed to CWE-197, including CVE-2022-42475, CVE-2026-115889 and CVE-2024-43639. 1 is listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### How do you prevent CWE-197?

Ensure that no casts, implicit or explicit, take place that move from a larger size primitive or a smaller size primitive.

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

Exploiting CWE-197 can lead to: Modify Memory, Varies by Context.

### Is CWE-197 actively exploited?

Yes. 1 CWE-197 vulnerability is in CISA's KEV catalog of actively exploited flaws, out of 97 recorded CVEs.

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

---

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