Skip to content
OpenAdvisories
Medium GHSA-gfgm-chr3-x6px RUSTSEC-2022-0074

prettytable-rs: Force cast a &Vec<T> to &[T] may lead to undefined behavior

Published Dec 30, 2022 · Updated Nov 8, 2023 · Assigned by GHSA

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

Affected packages

EcosystemPackageAffectedFixedRecord
crates.io prettytable-rs < 0.10.0 0.10.0 GHSA-gfgm-chr3-x6px
crates.io prettytable-rs >= 0.0.0-0, < 0.10.0 0.10.0 RUSTSEC-2022-0074

References