# GHSA-xrv3-jmcp-374j: zerovec incorrectly uses `#[repr(packed)]`

> Attackers can trigger illegal memory accesses in applications using the zerovec library due to incorrect struct packing assumptions, potentially leading to crashes or code execution.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 1 Jul 2024
- **Also known as:** RUSTSEC-2024-0347

## What is GHSA-xrv3-jmcp-374j?

GHSA-xrv3-jmcp-374j is a memory corruption vulnerability in zerovec, published on 1 Jul 2024. 

### Official description

The affected versions make unsafe memory accesses under the assumption that `#[repr(packed)]` has a guaranteed field order. 

The Rust specification does not guarantee this, and https://github.com/rust-lang/rust/pull/125360 (1.80.0-beta) starts 
reordering fields of `#[repr(packed)]` structs, leading to illegal memory accesses.

The patched versions `0.9.7` and `0.10.4` use `#[repr(C, packed)]`, which guarantees field order.

## Which versions are affected by GHSA-xrv3-jmcp-374j?

5 open source packages ship an affected version, including zerovec.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `zerovec` | crates.io | All versions | 0.9.7 |
| `zerovec` | crates.io | All versions | 0.9.7 |
| `zerovec` | crates.io | From 0.0.0-0 | 0.9.7, 0.10.4 |
| `zerovec` | crates.io | From 0.10.0 | 0.10.4 |
| `zerovec` | crates.io | From 0.10.0 | 0.10.4 |

## How do I fix GHSA-xrv3-jmcp-374j?

Upgrade zerovec to a fixed version for your release line: 0.9.7 or 0.10.4.

## Is GHSA-xrv3-jmcp-374j being exploited?

There is no known exploitation of GHSA-xrv3-jmcp-374j in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-xrv3-jmcp-374j and fix it if it is affected.

What it is: GHSA-xrv3-jmcp-374j is a memory corruption vulnerability in zerovec, published on 1 Jul 2024. 
Exploitation: There is no known exploitation of GHSA-xrv3-jmcp-374j in the wild and no public exploit code.

Affected packages and fixed versions:
- zerovec (crates.io): affected all versions; fixed in 0.9.7
- zerovec (crates.io): affected all versions; fixed in 0.9.7
- zerovec (crates.io): affected from 0.0.0-0; fixed in 0.9.7, 0.10.4
- zerovec (crates.io): affected from 0.10.0; fixed in 0.10.4
- zerovec (crates.io): affected from 0.10.0; fixed in 0.10.4

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-xrv3-jmcp-374j/ (Markdown: https://insights.sbomify.com/GHSA-xrv3-jmcp-374j/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-xrv3-jmcp-374j

---
From sbomify Insights: https://insights.sbomify.com/GHSA-xrv3-jmcp-374j/
Summaries are generated and may contain mistakes; the official description above is the record.
