# GHSA-74r5-g7vc-j2v2: zerovec-derive incorrectly uses `#[repr(packed)]`

> Attackers can trigger illegal memory accesses and potential code execution in applications using the zerovec-derive crate due to incorrect struct layout assumptions.

- **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-0346

## What is GHSA-74r5-g7vc-j2v2?

GHSA-74r5-g7vc-j2v2 is a memory corruption vulnerability in zerovec-derive, 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.3` use `#[repr(C, packed)]`, which guarantees field order.

## Which versions are affected by GHSA-74r5-g7vc-j2v2?

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


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

## How do I fix GHSA-74r5-g7vc-j2v2?

Upgrade zerovec-derive to a fixed version for your release line: 0.9.7 or 0.10.3.

## Is GHSA-74r5-g7vc-j2v2 being exploited?

There is no known exploitation of GHSA-74r5-g7vc-j2v2 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-74r5-g7vc-j2v2 and fix it if it is affected.

What it is: GHSA-74r5-g7vc-j2v2 is a memory corruption vulnerability in zerovec-derive, published on 1 Jul 2024. 
Exploitation: There is no known exploitation of GHSA-74r5-g7vc-j2v2 in the wild and no public exploit code.

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

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-74r5-g7vc-j2v2/ (Markdown: https://insights.sbomify.com/GHSA-74r5-g7vc-j2v2/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-74r5-g7vc-j2v2

---
From sbomify Insights: https://insights.sbomify.com/GHSA-74r5-g7vc-j2v2/
Summaries are generated and may contain mistakes; the official description above is the record.
