# GHSA-xfhw-6mc4-mgxf: crayon: ObjectPool creates uninitialized memory when freeing objects

> The crayon Rust library triggers undefined behavior by reading uninitialized memory during object pool cleanup, 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:** No
- **Published:** 27 Feb 2024
- **Also known as:** RUSTSEC-2024-0018

## What is GHSA-xfhw-6mc4-mgxf?

GHSA-xfhw-6mc4-mgxf is a memory corruption vulnerability in crayon, published on 27 Feb 2024. 

### Official description

As of version 0.6.0, the ObjectPool explicitly creates an uninitialized instance of its type parameter when it attempts to free an object, and swaps it into the storage. This causes instant undefined behavior due to reading the uninitialized memory in order to write it to the pool storage.

Extremely basic usage of the crate can trigger this issue, e.g. this code from a doctest:

```rust
use crayon::prelude::*;
application::oneshot().unwrap();

let mut params = MeshParams::default();

let mesh = video::create_mesh(params, None).unwrap();

// Deletes the mesh object.
video::delete_mesh(mesh); // <-- UB
```

The Clippy warning for this code was silenced in commit c2fde19caf6149d91faa504263f0bc5cafc35de5.

Discovered via https://asan.saethlin.dev/ub?crate=crayon&version=0.7.1

## Which versions are affected by GHSA-xfhw-6mc4-mgxf?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `crayon` | crates.io | From 0.6.0 | None |
| `crayon` | crates.io | From 0.6.0 to 0.7.1 | None |
| `crayon` | crates.io | From 0.6.0 to 0.7.1 | None |

## How do I fix GHSA-xfhw-6mc4-mgxf?

No fix has been published for GHSA-xfhw-6mc4-mgxf yet. Limit exposure of the affected software until one is available.

## Is GHSA-xfhw-6mc4-mgxf being exploited?

There is no known exploitation of GHSA-xfhw-6mc4-mgxf in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-xfhw-6mc4-mgxf and fix it if it is affected.

What it is: GHSA-xfhw-6mc4-mgxf is a memory corruption vulnerability in crayon, published on 27 Feb 2024. 
Exploitation: There is no known exploitation of GHSA-xfhw-6mc4-mgxf in the wild and no public exploit code.

Affected packages and fixed versions:
- crayon (crates.io): affected from 0.6.0; no fix listed
- crayon (crates.io): affected from 0.6.0 up to 0.7.1; no fix listed
- crayon (crates.io): affected from 0.6.0 up to 0.7.1; no fix listed

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-xfhw-6mc4-mgxf/ (Markdown: https://insights.sbomify.com/GHSA-xfhw-6mc4-mgxf/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-xfhw-6mc4-mgxf

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