# GHSA-fjx5-qpf4-xjf2: Parsing borsh messages with ZST which are not-copy/clone is unsound

> Attackers can cause segmentation faults or potential code execution by deserializing zero-sized types that lack Copy/Clone traits in the borsh 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:** 12 Apr 2023
- **Also known as:** RUSTSEC-2023-0033

## What is GHSA-fjx5-qpf4-xjf2?

GHSA-fjx5-qpf4-xjf2 is a memory corruption vulnerability in borsh, published on 12 Apr 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Affected versions of borsh cause undefined behavior when zero-sized-types (ZST) are parsed and the Copy/Clone traits are not implemented/derived. For instance if 1000 instances of a ZST are deserialized, and the ZST is not copy (this can be achieved through a singleton), then accessing/writing to deserialized data will cause a segmentation fault.

There is currently no way for borsh to read data without also providing a Rust type. Therefore, if you are not using ZST for serialization, then you are not affected by this issue.

## Which versions are affected by GHSA-fjx5-qpf4-xjf2?

3 open source packages ship an affected version, including borsh.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `borsh` | crates.io | All versions | 1.0.0-alpha.1 |
| `borsh` | crates.io | All versions | 1.0.0-alpha.1 |
| `borsh` | crates.io | From 0.0.0-0 | 0.10.4, 1.0.0-alpha.1 |

## How do I fix GHSA-fjx5-qpf4-xjf2?

Upgrade borsh to a fixed version for your release line: 1.0.0-alpha.1 or 0.10.4.

## Is GHSA-fjx5-qpf4-xjf2 being exploited?

There is no known exploitation of GHSA-fjx5-qpf4-xjf2 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-fjx5-qpf4-xjf2 and fix it if it is affected.

What it is: GHSA-fjx5-qpf4-xjf2 is a memory corruption vulnerability in borsh, published on 12 Apr 2023. 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-fjx5-qpf4-xjf2 in the wild and no public exploit code.

Affected packages and fixed versions:
- borsh (crates.io): affected all versions; fixed in 1.0.0-alpha.1
- borsh (crates.io): affected all versions; fixed in 1.0.0-alpha.1
- borsh (crates.io): affected from 0.0.0-0; fixed in 0.10.4, 1.0.0-alpha.1

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-fjx5-qpf4-xjf2/ (Markdown: https://insights.sbomify.com/GHSA-fjx5-qpf4-xjf2/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-fjx5-qpf4-xjf2

---
From sbomify Insights: https://insights.sbomify.com/GHSA-fjx5-qpf4-xjf2/
Summaries are generated and may contain mistakes; the official description above is the record.
