{"id":"GHSA-gfgm-chr3-x6px","aliases":["GHSA-gfgm-chr3-x6px","RUSTSEC-2022-0074"],"related":[],"kind":"vulnerability","state":"published","title":"prettytable-rs: Force cast a &Vec<T> to &[T] may lead to undefined behavior","summary":"In function `Table::as_ref`, a reference of vector is force cast to slice. There are multiple problems here:\n1. 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).\n2. 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).","summaryFormat":"markdown","summarySource":"ghsa","descriptions":[{"lang":"en","text":"In function `Table::as_ref`, a reference of vector is force cast to slice. There are multiple problems here:\n1. 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).\n2. 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).","format":"markdown","source":"ghsa"},{"lang":"en","text":"In function `Table::as_ref`, a reference of vector is force cast to slice. There are multiple problems here:\n1. 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.\n2. Even if (1) is sound, `&Vec<T>` and `&[T]` still might not have the same layout. Treating them equally may lead to UB.","format":"markdown","source":"rustsec"}],"published":"2022-12-02T12:00:00.000Z","modified":"2023-11-08T04:19:29.041Z","severity":{"scorer":"GitHub","scheme":"rating","rating":"MEDIUM"},"severities":[{"scorer":"GitHub","scheme":"rating","rating":"MEDIUM"}],"cwes":[],"affected":[{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.10.0"}],"ecosystem":"crates.io","package":"prettytable-rs","purl":"pkg:cargo/prettytable-rs","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0.0.0-0","status":"affected","fixed":"0.10.0"}],"ecosystem":"crates.io","package":"prettytable-rs","purl":"pkg:cargo/prettytable-rs","source":"rustsec"}],"references":[{"url":"https://github.com/phsym/prettytable-rs/issues/145","tags":["report","web"],"sources":["ghsa","rustsec"]},{"url":"https://github.com/phsym/prettytable-rs","tags":["package"],"sources":["ghsa"]},{"url":"https://rustsec.org/advisories/RUSTSEC-2022-0074.html","tags":["advisory","web"],"sources":["ghsa","rustsec"]},{"url":"https://crates.io/crates/prettytable-rs","tags":["package"],"sources":["rustsec"]}],"credits":[],"sources":[{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-gfgm-chr3-x6px","url":"https://github.com/advisories/GHSA-gfgm-chr3-x6px","licence":"CC-BY-4.0","modified":"2023-11-08T04:19:29.041Z"},{"source":"rustsec","name":"RustSec Advisory Database","id":"RUSTSEC-2022-0074","url":"https://rustsec.org/advisories/RUSTSEC-2022-0074.html","licence":"CC0-1.0","modified":"2023-11-08T04:19:29.041Z"}],"updatedAt":"2026-11-25T22:56:43.117Z"}