# GHSA-7fqq-q52p-2jjg: OpenCC has an Out-of-bounds read when processing truncated UTF-8 input

> An attacker can cause crashes or leak memory by providing truncated UTF-8 input to the OpenCC library.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 29 Mar 2026

## What is GHSA-7fqq-q52p-2jjg?

GHSA-7fqq-q52p-2jjg is a memory corruption vulnerability in OpenCC, published on 29 Mar 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

### Summary

OpenCC versions before 1.2.0 contain two `CWE-125: Out-of-bounds Read` issues caused by length validation failures in UTF-8 processing. When handling malformed or truncated UTF-8 input, OpenCC trusted derived length values without enforcing the invariant that processed length must not exceed the remaining input buffer. This could result in out-of-bounds reads during segmentation or conversion.

### Details

Two independent code paths in OpenCC failed to enforce the invariant:

`matchedLength <= remainingLength`

Both paths assumed derived length values were valid and within input bounds, but did not validate that assumption against the remaining buffer. This created the following failure chain:

`invalid UTF-8 -> incorrect derived length -> incorrect pointer advance -> remaining-length desynchronization -> out-of-bounds read`

In `MaxMatchSegmentation::Segment`, this could desynchronize remaining-length tracking and cause out-of-bounds reads during prefix matching.

In `Conversion::Convert(const char*)`, similar logic could advance processing past the end of the input string and read beyond the null terminator into adjacent memory. In some cases, unintended heap bytes could be propagated into the conversion result.

PR #1005 fixes both issues by explicitly tracking input boundaries, recomputing remaining length on each iteration, and clamping processed lengths so the buffer-bound invariant is preserved.

Affected versions:

* All versions before 1.2.0

Patched version:

* 1.2.0

### PoC

Build a vulnerable version with AddressSanitizer enabled and process input ending with a truncated UTF-8 sequence, such as a missing final byte of a 3-byte character. The original report and ASan reproduction are available in [Issue #997](https://github.com/BYVoid/OpenCC/issues/997).

### Impact

This vulnerability may cause process crashes and limited, non-deterministic information disclosure when OpenCC processes malformed or attacker-controlled UTF-8 input. The issue does not indicate arbitrary write or code execution.

OpenCC is distributed through system and language-specific package managers, prebuilt binaries, container images, and downstream software, so affected versions may be present even when it is not listed as a direct dependency. Users should upgrade all installed or bundled copies of OpenCC to 1.2.0 or later.

### Credit

OpenCC thanks @oneafter for reporting the issue.

## Which versions are affected by GHSA-7fqq-q52p-2jjg?

4 open source packages ship an affected version, including opencc and OpenCC.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `opencc` | PyPI | All versions | 1.2.0 |
| `opencc` | npm | All versions | 1.2.0 |
| `opencc` | npm | All versions | 1.2.0 |
| `OpenCC` | PyPI | All versions | 1.2.0 |

## How do I fix GHSA-7fqq-q52p-2jjg?

Upgrade opencc to 1.2.0 or later.

## Is GHSA-7fqq-q52p-2jjg being exploited?

There is no known exploitation of GHSA-7fqq-q52p-2jjg in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-7fqq-q52p-2jjg and fix it if it is affected.

What it is: GHSA-7fqq-q52p-2jjg is a memory corruption vulnerability in OpenCC, published on 29 Mar 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-7fqq-q52p-2jjg in the wild and no public exploit code.

Affected packages and fixed versions:
- opencc (PyPI): affected all versions; fixed in 1.2.0
- opencc (npm): affected all versions; fixed in 1.2.0
- opencc (npm): affected all versions; fixed in 1.2.0
- OpenCC (PyPI): affected all versions; fixed in 1.2.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-7fqq-q52p-2jjg/ (Markdown: https://insights.sbomify.com/GHSA-7fqq-q52p-2jjg/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-7fqq-q52p-2jjg

---
From sbomify Insights: https://insights.sbomify.com/GHSA-7fqq-q52p-2jjg/
Summaries are generated and may contain mistakes; the official description above is the record.
