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.
- Exploited in the wild
- Not known
- Login needed
- Not needed
- Attackable
- Not stated
- Victim action needed
- Not needed
- Fix
- Available
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:
- 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). - 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 | 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.
Upgrade to the fixed version. Memory-safe languages, compiler hardening and fuzzing prevent most new cases. More about Memory corruption.
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.
Sources
Also known as RUSTSEC-2022-0074.