# GHSA-h6xm-c6r4-vmwf: Unsound usages of `u8` type casting in spl-token-swap

> Unsound u8 casting in spl-token-swap allows misaligned pointer dereference or illegal type construction, potentially causing panics or undefined behavior.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** No
- **Published:** 19 Dec 2024
- **Also known as:** RUSTSEC-2024-0426

## What is GHSA-h6xm-c6r4-vmwf?

GHSA-h6xm-c6r4-vmwf is a memory corruption vulnerability in spl-token-swap, published on 19 Dec 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

The library provides a safe public API `unpack` to cast `u8` array to arbitrary types, which can cause to undefined behaviors. The length check of array can only prevent out-of-bound access on the return type. However, it can't prevent misaligned pointer when casting `u8` pointer to a type aligned to larger bytes. For example, if we assign `u16` to `T`, **misaligned raw pointer dereference** could happen and cause to panic. Even if we pass the type aligned to same byte as `u8` (e.g., `bool`), it could construct a illegal type since `bool` can only have 0 or 1 as bit patterns, which is also an undefined behavior. The further exploits of the bug here are still not clear, so we would report this issue as unsound.  

The details of PoC to reproduce undefined behavior are provided in the [issue](https://github.com/solana-labs/solana-program-library/issues/5243).

## Which versions are affected by GHSA-h6xm-c6r4-vmwf?

3 open source packages ship an affected version, including spl-token-swap.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `spl-token-swap` | crates.io | All versions to 3.0.0 | None |
| `spl-token-swap` | crates.io | All versions to 3.0.0 | None |
| `spl-token-swap` | crates.io | From 0.0.0-0 | None |

## How do I fix GHSA-h6xm-c6r4-vmwf?

No fix has been published for GHSA-h6xm-c6r4-vmwf yet. Limit exposure of the affected software until one is available.

## Is GHSA-h6xm-c6r4-vmwf being exploited?

There is no known exploitation of GHSA-h6xm-c6r4-vmwf in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-h6xm-c6r4-vmwf and fix it if it is affected.

What it is: GHSA-h6xm-c6r4-vmwf is a memory corruption vulnerability in spl-token-swap, published on 19 Dec 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-h6xm-c6r4-vmwf in the wild and no public exploit code.

Affected packages and fixed versions:
- spl-token-swap (crates.io): affected all versions up to 3.0.0; no fix listed
- spl-token-swap (crates.io): affected all versions up to 3.0.0; no fix listed
- spl-token-swap (crates.io): affected from 0.0.0-0; 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-h6xm-c6r4-vmwf/ (Markdown: https://insights.sbomify.com/GHSA-h6xm-c6r4-vmwf/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-h6xm-c6r4-vmwf

---
From sbomify Insights: https://insights.sbomify.com/GHSA-h6xm-c6r4-vmwf/
Summaries are generated and may contain mistakes; the official description above is the record.
