# GHSA-7v4j-8wvr-v55r: `array!` macro is unsound when its length is impure constant

> Unsound array initialization via impure constants allows arbitrary code execution in Rust applications using the affected macro.

- **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:** 27 Apr 2022
- **Also known as:** RUSTSEC-2022-0017

## What is GHSA-7v4j-8wvr-v55r?

GHSA-7v4j-8wvr-v55r is a memory corruption vulnerability in array-macro, published on 27 Apr 2022. 

### Official description

Affected versions of this crate did substitute the array length provided by an user at compile-time multiple times.

When an impure constant expression is passed as an array length (such as a result of an impure procedural macro), this can result in the initialization of an array with uninitialized types, which in turn can allow an attacker to execute arbitrary code.

The flaw was corrected in commit [d5b63f72](https://gitlab.com/KonradBorowski/array-macro/-/commit/d5b63f72090f3809c21ac28f9cfd84f12559bf7d) by making sure that array length is substituted just once.

## Which versions are affected by GHSA-7v4j-8wvr-v55r?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `array-macro` | crates.io | From 2.1.0 | 2.1.2 |
| `array-macro` | crates.io | From 2.1.0 | 2.1.2 |
| `array-macro` | crates.io | From 2.1.0 | 2.1.2 |

## How do I fix GHSA-7v4j-8wvr-v55r?

Upgrade array-macro to 2.1.2 or later.

## Is GHSA-7v4j-8wvr-v55r being exploited?

There is no known exploitation of GHSA-7v4j-8wvr-v55r in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-7v4j-8wvr-v55r and fix it if it is affected.

What it is: GHSA-7v4j-8wvr-v55r is a memory corruption vulnerability in array-macro, published on 27 Apr 2022. 
Exploitation: There is no known exploitation of GHSA-7v4j-8wvr-v55r in the wild and no public exploit code.

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

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-7v4j-8wvr-v55r/ (Markdown: https://insights.sbomify.com/GHSA-7v4j-8wvr-v55r/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-7v4j-8wvr-v55r

---
From sbomify Insights: https://insights.sbomify.com/GHSA-7v4j-8wvr-v55r/
Summaries are generated and may contain mistakes; the official description above is the record.
