# GHSA-83gg-pwxf-jr89: `array!` macro is unsound in presence of traits that implement methods it calls internally

> A Rust library vulnerability allows trait implementations to hijack internal method calls, potentially leading to memory unsoundness and arbitrary code execution.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 7 May 2020
- **Also known as:** RUSTSEC-2020-0161

## What is GHSA-83gg-pwxf-jr89?

GHSA-83gg-pwxf-jr89 is a code injection vulnerability in array-macro, published on 7 May 2020. 

### Official description

Affected versions of this crate called some methods using auto-ref. The affected code looked like this.

```rust
let mut arr = $crate::__core::mem::MaybeUninit::uninit();
let mut vec = $crate::__ArrayVec::<T>::new(arr.as_mut_ptr() as *mut T);
```

In this case, the problem is that `as_mut_ptr` is a method of `&mut MaybeUninit`, not `MaybeUninit`. This made it possible for traits to hijack the method calls in order to cause unsoundness.

```rust
trait AsMutPtr<T> {
    fn as_mut_ptr(&self) -> *mut T;
}
impl<T> AsMutPtr<T> for std::mem::MaybeUninit<T> {
    fn as_mut_ptr(&self) -> *mut T {
        std::ptr::null_mut()
    }
}
array![0; 1];
```

The flaw was corrected by explicitly referencing variables in macro body in order to avoid auto-ref.

## Which versions are affected by GHSA-83gg-pwxf-jr89?

3 open source packages ship an affected version, including array-macro.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `array-macro` | crates.io | From 0.1.2 | 1.0.5 |
| `array-macro` | crates.io | From 0.1.2 | 1.0.5 |
| `array-macro` | crates.io | From 0.1.2 | 1.0.5 |

## How do I fix GHSA-83gg-pwxf-jr89?

Upgrade array-macro to 1.0.5 or later.

## Is GHSA-83gg-pwxf-jr89 being exploited?

There is no known exploitation of GHSA-83gg-pwxf-jr89 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-83gg-pwxf-jr89 and fix it if it is affected.

What it is: GHSA-83gg-pwxf-jr89 is a code injection vulnerability in array-macro, published on 7 May 2020. 
Exploitation: There is no known exploitation of GHSA-83gg-pwxf-jr89 in the wild and no public exploit code.

Affected packages and fixed versions:
- array-macro (crates.io): affected from 0.1.2; fixed in 1.0.5
- array-macro (crates.io): affected from 0.1.2; fixed in 1.0.5
- array-macro (crates.io): affected from 0.1.2; fixed in 1.0.5

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-83gg-pwxf-jr89/ (Markdown: https://insights.sbomify.com/GHSA-83gg-pwxf-jr89/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-83gg-pwxf-jr89

---
From sbomify Insights: https://insights.sbomify.com/GHSA-83gg-pwxf-jr89/
Summaries are generated and may contain mistakes; the official description above is the record.
