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

Not scored Published

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:

  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, &amp;Vec&lt;T&gt; and &amp;[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.

PackageAffectedFixed in
prettytable-rs crates.ioAll versions0.10.0
prettytable-rs crates.ioAll versions0.10.0
prettytable-rs crates.ioFrom 0.0.0-00.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.

Is GHSA-gfgm-chr3-x6px in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free