GHSA-gfgm-chr3-x6px
medium
prettytable-rs: Force cast a &Vec<T> to &[T] may lead to undefined behavior
- Severity
- medium rating by GitHub
- Published
- Last changed
- 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:
- 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).
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| prettytable-rs (crates.io) | before 0.10.0, from 0.0.0-0 before 0.10.0 | GitHub Advisory Database, RustSec Advisory Database |
What each source says
GitHub Advisory Database
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).
RustSec Advisory Database
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 UB. - Even if (1) is sound,
&Vec<T>and&[T]still might not have the same layout. Treating them equally may lead to UB.
References
Sources
| Source | Record | Licence |
|---|---|---|
| GitHub Advisory Database | GHSA-gfgm-chr3-x6px changed 2023-11-08 | CC-BY-4.0 |
| RustSec Advisory Database | RUSTSEC-2022-0074 changed 2023-11-08 | CC0-1.0 |