---
title: "CWE-128: Wrap-around Error"
url: https://radicalnotion.ai/cwe/cwe-128
type: cwe
description: "Wrap around errors occur whenever a value is incremented past the maximum value for its type and therefore \"wraps around\" to a very small, negative, or undefined value."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-128: Wrap-around Error

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

## Description

Wrap around errors occur whenever a value is incremented past the maximum value for its type and therefore "wraps around" to a very small, negative, or undefined value.

## Background

Due to how addition is performed by computers, if a primitive is incremented past the maximum value possible for its storage space, the system will not recognize this, and therefore increment each bit as if it still had extra space. Because of how negative numbers are represented in binary, primitives interpreted as signed may "wrap" to very large negative values.

## Modes of introduction

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

## Applicable platforms

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

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability | DoS: Crash, Exit, or Restart, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Instability | This weakness will generally lead to undefined behavior and therefore crashes. In the case of overflows involving loop index variables, the likelihood of infinite loops is also high. |
| Integrity | Modify Memory | If the value in question is important to data (as opposed to flow), simple data corruption has occurred. Also, if the wrap around results in other conditions such as buffer overflows, further memory corruption may occur. |
| Confidentiality, Availability, Access Control | Execute Unauthorized Code or Commands, Bypass Protection Mechanism | This weakness can sometimes trigger buffer overflows which can be used to execute arbitrary code. This is usually outside the scope of a program's implicit security policy. |

## Potential mitigations

### Mitigation

Requirements specification: The choice could be made to use a language that is not susceptible to these issues.

### Architecture and Design

Provide clear upper and lower bounds on the scale of any protocols designed.

### Implementation

Perform validation on all incremented variables to ensure that they remain within reasonable bounds.

## 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 image processing code allocates a table for images.

Bad code:

```c
img_t table_ptr; /*struct containing img data, 10kB each*/
int num_imgs;
...
num_imgs = get_num_imgs();
table_ptr = (img_t*)malloc(sizeof(img_t)*num_imgs);
...
```

This code intends to allocate a table of size num\_imgs, however as num\_imgs grows large, the calculation determining the size of the list will eventually overflow (CWE-190). This will result in a very small list to be allocated instead. If the subsequent code operates on the list as if it were num\_imgs long, it may result in many types of out-of-bounds problems (CWE-119).

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2024-23981 | - | critical | 9.3 | - | No | 2024-08-14 |
| CVE-2026-16909 | Vulnerabilities in IBM AIX and PowerVM VIOS | high | 8.8 | - | No | 2026-08-19 |
| CVE-2022-35258 | - | high | 7.5 | - | No | 2022-12-05 |
| CVE-2026-20179 | Multiple Cisco Products Snort 3 Generic Routing Encapsulation Denial of Service Vulnerabilities | medium | 5.8 | - | No | 2026-10-21 |
| CVE-2026-54905 | concurrent-ruby: \`ReentrantReadWriteLock\` read-count overflow grants a write lock without exclusivity | low | 2.0 | - | No | 2026-06-24 |

## Related attack patterns (CAPEC)

- [CAPEC-92](https://radicalnotion.ai/capec/capec-92): Forced Integer Overflow

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-682](https://radicalnotion.ai/cwe/cwe-682) | Incorrect Calculation |
| Peer | [CWE-190](https://radicalnotion.ai/cwe/cwe-190) | Integer Overflow or Wraparound |
| Can precede | [CWE-119](https://radicalnotion.ai/cwe/cwe-119) | Improper Restriction of Operations within the Bounds of a Memory Buffer |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CLASP | Wrap-around error | - | - |
| CERT C Secure Coding | Ensure that the arguments to calloc(), when multiplied, can be represented as a size\_t | MEM07-C | - |
| Software Fault Patterns | Glitch in computation | SFP1 | - |
| PLC Top 20 | Use PLC flags as integrity checks | 4 | - |

## Frequently asked questions

### What is CWE-128?

Wrap around errors occur whenever a value is incremented past the maximum value for its type and therefore "wraps around" to a very small, negative, or undefined value.

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

5 recorded CVEs are attributed to CWE-128, including CVE-2024-23981, CVE-2026-16909 and CVE-2022-35258.

### How do you prevent CWE-128?

Requirements specification: The choice could be made to use a language that is not susceptible to these issues.

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

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

### Is CWE-128 actively exploited?

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

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

---

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