# CVE-2021-41253: Possible heap buffer overflow when using zycore string functions in formatter hooks

> Heap buffer overflow in Zydis library allows attackers to corrupt memory via custom formatter hooks using zycore string functions.

- **Severity:** Medium 5.9 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 8 Nov 2021
- **Updated:** 4 Aug 2024
- **Also known as:** DEBIAN-CVE-2021-41253, GHSA-q42v-hv86-3m4g

## What is CVE-2021-41253?

CVE-2021-41253 is a medium-severity memory corruption vulnerability in zyantific zydis, published on 8 Nov 2021. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Zydis is an x86/x86-64 disassembler library. Users of Zydis versions v3.2.0 and older that use the string functions provided in `zycore` in order to append untrusted user data to the formatter buffer within their custom formatter hooks can run into heap buffer overflows. Older versions of Zydis failed to properly initialize the string object within the formatter buffer, forgetting to initialize a few fields, leaving their value to chance. This could then in turn cause zycore functions like `ZyanStringAppend` to make incorrect calculations for the new target size, resulting in heap memory corruption. This does not affect the regular uncustomized Zydis formatter, because Zydis internally doesn't use the string functions in zycore that act upon these fields. However, because the zycore string functions are the intended way to work with the formatter buffer for users of the library that wish to extend the formatter, we still consider this to be a vulnerability in Zydis. This bug is patched starting in version 3.2.1. As a workaround, users may refrain from using zycore string functions in their formatter hooks until updating to a patched version.

Weakness: CWE-908 (Use of Uninitialized Resource), CWE-457 (Use of Uninitialized Variable), CWE-122 (Heap-based Buffer Overflow)

## Which versions are affected by CVE-2021-41253?

It affects 1 product.


Products: Zyantific Zydis.

## How do I fix CVE-2021-41253?

Upgrade to a fixed version.

## Is CVE-2021-41253 being exploited?

There is no known exploitation of CVE-2021-41253 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-41253 and fix it if it is affected.

What it is: CVE-2021-41253 is a medium-severity memory corruption vulnerability in zyantific zydis, published on 8 Nov 2021. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2021-41253 in the wild and no public exploit code.

Affected product: zyantific zydis. No package-level version data is available, so check the vendor advisory linked from the reference page.

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/CVE-2021-41253/ (Markdown: https://insights.sbomify.com/CVE-2021-41253/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2021-41253
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2021-41253
- OSV: https://osv.dev/vulnerability/CVE-2021-41253

---
From sbomify Insights: https://insights.sbomify.com/CVE-2021-41253/
Summaries are generated and may contain mistakes; the official description above is the record.
