---
title: "CWE-135: Incorrect Calculation of Multi-Byte String Length"
url: https://radicalnotion.ai/cwe/cwe-135
type: cwe
description: "The product does not correctly calculate the length of strings that can contain wide or multi-byte characters."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-135: Incorrect Calculation of Multi-Byte String Length

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 2
- **Of those, in CISA KEV:** 0
- **New in 2026:** 2
- **CWE catalog version:** 4.21

## Description

The product does not correctly calculate the length of strings that can contain wide or multi-byte characters.

## Modes of introduction

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

## Applicable platforms

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

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Confidentiality, Availability | Execute Unauthorized Code or Commands | This weakness may lead to a buffer overflow. Buffer overflows often can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy. This can often be used to subvert any other security service. |
| Availability, Confidentiality | Read Memory, DoS: Crash, Exit, or Restart, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory) | Out of bounds memory access will very likely result in the corruption of relevant memory, and perhaps instructions, possibly leading to a crash. Other attacks leading to lack of availability are possible, including putting the program into an infinite loop. |
| Confidentiality | Read Memory | In the case of an out-of-bounds read, the attacker may have access to sensitive information. If the sensitive information contains system details, such as the current buffer's position in memory, this knowledge can be used to craft further attacks, possibly with more severe consequences. |

## Potential mitigations

### Implementation (Input Validation)

Always verify the length of the string unit character.

### Implementation (Libraries or Frameworks)

Use length computing functions (e.g. strlen, wcslen, etc.) appropriately with their equivalent type (e.g.: byte, wchar\_t, etc.)

## 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 example would be exploitable if any of the commented incorrect malloc calls were used.

Bad code:

```c
#include <stdio.h>
#include <strings.h>
#include <wchar.h>

int main() {

    wchar_t wideString[] = L"The spazzy orange tiger jumped " \
    "over the tawny jaguar.";
    wchar_t *newString;

    printf("Strlen() output: %d\nWcslen() output: %d\n",
    strlen(wideString), wcslen(wideString));

    /* Wrong because the number of chars in a string isn't related to its length in bytes //
    newString = (wchar_t *) malloc(strlen(wideString));
    */

    /* Wrong because wide characters aren't 1 byte long! //
    newString = (wchar_t *) malloc(wcslen(wideString));
    */

    /* Wrong because wcslen does not include the terminating null */
    newString = (wchar_t *) malloc(wcslen(wideString) * sizeof(wchar_t));

    /* correct! */
    newString = (wchar_t *) malloc((wcslen(wideString) + 1) * sizeof(wchar_t));

    /* ... */
}
```

Result code:

```
Strlen() output: 0
Wcslen() output: 53
```

The output from the printf() statement would be:

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-0810 | Gix-date: gix-date: undefined behavior due to invalid string generation | medium | 5.5 | - | No | 2026-01-26 |
| CVE-2026-128085 | opentelemetry-go: AttributeValueLengthLimit is fully bypassed by attribute values composed of valid U+FFFD runes | medium | 5.3 | - | No | 2026-11-13 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-682](https://radicalnotion.ai/cwe/cwe-682) | Incorrect Calculation |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CLASP | Improper string length checking | - | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Ensure the array is filled when using read() to fill an array | FIO10-J | - |
| Software Fault Patterns | Incorrect Buffer Length Computation | SFP10 | - |

## Frequently asked questions

### What is CWE-135?

The product does not correctly calculate the length of strings that can contain wide or multi-byte characters.

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

2 recorded CVEs are attributed to CWE-135, including CVE-2026-0810 and CVE-2026-128085.

### How do you prevent CWE-135?

Always verify the length of the string unit character.

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

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

### Is CWE-135 actively exploited?

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

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

---

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