# GHSA-gfgm-chr3-x6px: prettytable-rs: Force cast a &Vec<T> to &[T] may lead to undefined behavior

> Undefined behavior in prettytable-rs due to unsafe casting of Vec to slice, potentially allowing code execution or crashes.

- **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:** 2 Dec 2022
- **Also known as:** RUSTSEC-2022-0074

## What is GHSA-gfgm-chr3-x6px?

GHSA-gfgm-chr3-x6px is a memory corruption vulnerability in prettytable-rs, published on 2 Dec 2022. 

### Official description

In function `Table::as_ref`, a reference of vector is force cast to slice. There are multiple problems here:
1. To guarantee the size is correct, we have to first do `Vec::shrink_to_fit`. The function requires a mutable reference, so we have to force cast from immutable to mutable, which is undefined behavior (UB).
2. Even if (1) is sound, `&Vec<T>` and `&[T]` still might not have the same layout. Treating them equally may lead to undefinted behavior (UB).

## Which versions are affected by GHSA-gfgm-chr3-x6px?

3 open source packages ship an affected version, including prettytable-rs.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `prettytable-rs` | crates.io | All versions | 0.10.0 |
| `prettytable-rs` | crates.io | All versions | 0.10.0 |
| `prettytable-rs` | crates.io | From 0.0.0-0 | 0.10.0 |

## How do I fix GHSA-gfgm-chr3-x6px?

Upgrade prettytable-rs to 0.10.0 or later.

## Is GHSA-gfgm-chr3-x6px being exploited?

There is no known exploitation of GHSA-gfgm-chr3-x6px in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-gfgm-chr3-x6px and fix it if it is affected.

What it is: GHSA-gfgm-chr3-x6px is a memory corruption vulnerability in prettytable-rs, published on 2 Dec 2022. 
Exploitation: There is no known exploitation of GHSA-gfgm-chr3-x6px in the wild and no public exploit code.

Affected packages and fixed versions:
- prettytable-rs (crates.io): affected all versions; fixed in 0.10.0
- prettytable-rs (crates.io): affected all versions; fixed in 0.10.0
- prettytable-rs (crates.io): affected from 0.0.0-0; fixed in 0.10.0

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-gfgm-chr3-x6px/ (Markdown: https://insights.sbomify.com/GHSA-gfgm-chr3-x6px/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-gfgm-chr3-x6px

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