# GHSA-h7h7-6mx3-r89v: Unsound usages of `Vec::from_raw_parts`

> Unsound memory transmutation in Fyrox engine library allows attackers to trigger undefined behavior and potential code execution via crafted data.

- **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:** 19 Dec 2024
- **Also known as:** RUSTSEC-2024-0435

## What is GHSA-h7h7-6mx3-r89v?

GHSA-h7h7-6mx3-r89v is a memory corruption vulnerability in fyrox-core, published on 19 Dec 2024. 

### Official description

The library provides a public safe API `transmute_vec_as_bytes`, which incorrectly assumes that any generic type `T` could have stable layout, causing to uninitialized memory exposure if the users pass any types with padding bytes as `T` and cast it to `u8` pointer.  

In the [issue](https://github.com/FyroxEngine/Fyrox/issues/630), we develop a PoC to show passing struct type to `transmute_vec_as_bytes` could lead to undefined behavior with `Vec::from_raw_parts`.  

The developers provide a patch by changing trait of `Copy` to `Pod`, which can make sure `T` should be plain data. This was patched in the latest version of [master](https://github.com/FyroxEngine/Fyrox/blob/3f9ad6f9667047dac051b0e97d544e5b38e5ae72/fyrox-core/src/lib.rs#L351-L360) branch, but still not on the latest release (0.28.1).

## Which versions are affected by GHSA-h7h7-6mx3-r89v?

3 open source packages ship an affected version, including fyrox-core.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `fyrox-core` | crates.io | From 0.0.0-0 | 0.36.0 |
| `fyrox-core` | crates.io | From 0.28.1 | 0.36 |
| `fyrox-core` | crates.io | From 0.28.1 | 0.36 |

## How do I fix GHSA-h7h7-6mx3-r89v?

Upgrade fyrox-core to a fixed version for your release line: 0.36.0 or 0.36.

## Is GHSA-h7h7-6mx3-r89v being exploited?

There is no known exploitation of GHSA-h7h7-6mx3-r89v in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-h7h7-6mx3-r89v and fix it if it is affected.

What it is: GHSA-h7h7-6mx3-r89v is a memory corruption vulnerability in fyrox-core, published on 19 Dec 2024. 
Exploitation: There is no known exploitation of GHSA-h7h7-6mx3-r89v in the wild and no public exploit code.

Affected packages and fixed versions:
- fyrox-core (crates.io): affected from 0.0.0-0; fixed in 0.36.0
- fyrox-core (crates.io): affected from 0.28.1; fixed in 0.36
- fyrox-core (crates.io): affected from 0.28.1; fixed in 0.36

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-h7h7-6mx3-r89v/ (Markdown: https://insights.sbomify.com/GHSA-h7h7-6mx3-r89v/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-h7h7-6mx3-r89v

---
From sbomify Insights: https://insights.sbomify.com/GHSA-h7h7-6mx3-r89v/
Summaries are generated and may contain mistakes; the official description above is the record.
