# GHSA-wfg4-322g-9vqv: memoffset allows reading uninitialized memory

> The memoffset library allows reading uninitialized memory, potentially causing undefined behavior, crashes, or code execution in Rust applications.

- **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:** 21 Jun 2023
- **Also known as:** RUSTSEC-2023-0045

## What is GHSA-wfg4-322g-9vqv?

GHSA-wfg4-322g-9vqv is a memory corruption vulnerability in memoffset, published on 21 Jun 2023. 

### Official description

memoffset allows attempt of reading data from address `0` with arbitrary type. This behavior is an undefined behavior because address `0` to `std::mem::size_of<T>` may not have valid bit-pattern with `T`. Old implementation dereferences uninitialized memory obtained from `std::mem::align_of`. Older implementation prior to it allows using uninitialized data obtained from `std::mem::uninitialized` with arbitrary type then compute offset by taking the address of field-projection. This may also result in an undefined behavior for "father" that includes (directly or transitively) type that [does not allow to be uninitialized](https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html).

This flaw was corrected by using `std::ptr::addr_of` in <https://github.com/Gilnaa/memoffset/pull/50>.

## Which versions are affected by GHSA-wfg4-322g-9vqv?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `memoffset` | crates.io | All versions | 0.6.2 |
| `memoffset` | crates.io | All versions | 0.6.2 |
| `memoffset` | crates.io | From 0.0.0-0 | 0.6.2 |

## How do I fix GHSA-wfg4-322g-9vqv?

Upgrade memoffset to 0.6.2 or later.

## Is GHSA-wfg4-322g-9vqv being exploited?

There is no known exploitation of GHSA-wfg4-322g-9vqv in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-wfg4-322g-9vqv and fix it if it is affected.

What it is: GHSA-wfg4-322g-9vqv is a memory corruption vulnerability in memoffset, published on 21 Jun 2023. 
Exploitation: There is no known exploitation of GHSA-wfg4-322g-9vqv in the wild and no public exploit code.

Affected packages and fixed versions:
- memoffset (crates.io): affected all versions; fixed in 0.6.2
- memoffset (crates.io): affected all versions; fixed in 0.6.2
- memoffset (crates.io): affected from 0.0.0-0; fixed in 0.6.2

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-wfg4-322g-9vqv/ (Markdown: https://insights.sbomify.com/GHSA-wfg4-322g-9vqv/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-wfg4-322g-9vqv

---
From sbomify Insights: https://insights.sbomify.com/GHSA-wfg4-322g-9vqv/
Summaries are generated and may contain mistakes; the official description above is the record.
