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

- Severity: Medium (rating, scored by GitHub)
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Published: 2022-12-02T12:00:00.000Z
- Modified: 2023-11-08T04:19:29.041Z
- Also known as: RUSTSEC-2022-0074

## 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).

(As written by GitHub Advisory Database.)

## Affected

- prettytable-rs (crates.io): before 0.10.0; from 0.0.0-0 before 0.10.0

## References

- <https://github.com/phsym/prettytable-rs/issues/145> (report, web)
- <https://github.com/phsym/prettytable-rs> (package)
- <https://rustsec.org/advisories/RUSTSEC-2022-0074.html> (advisory, web)
- <https://crates.io/crates/prettytable-rs> (package)

## Sources

- GitHub Advisory Database: [GHSA-gfgm-chr3-x6px](https://github.com/advisories/GHSA-gfgm-chr3-x6px), CC-BY-4.0, modified 2023-11-08
- RustSec Advisory Database: [RUSTSEC-2022-0074](https://rustsec.org/advisories/RUSTSEC-2022-0074.html), CC0-1.0, modified 2023-11-08

---

Page: https://cve.day/GHSA-gfgm-chr3-x6px · Whole record: https://cve.day/GHSA-gfgm-chr3-x6px.json · Rebuilt by cve.day 2026-11-25T22:56:43.117Z
