# GHSA-fq33-vmhv-48xh: ntru-rs has unsound FFI: Wrong API usage causes write past allocated area

> Incorrect API usage in ntru-rs causes memory corruption, potentially leading to code execution or crashes.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** No
- **Published:** 22 Mar 2023
- **Also known as:** RUSTSEC-2023-0032

## What is GHSA-fq33-vmhv-48xh?

GHSA-fq33-vmhv-48xh is a memory corruption vulnerability in ntru, published on 22 Mar 2023. 

### Official description

The following usage causes undefined behavior.
```rust
let kp: ntru::types::KeyPair = …;
kp.get_public().export(Default::default())
```

When compiled with debug assertions, the code above will trigger a `attempt to subtract with overflow` panic before UB occurs.
Other mistakes (e.g. using `EncParams` from a different key) may always trigger UB.

Likely, older versions of this crate are also affected, but have not been tested.

## Which versions are affected by GHSA-fq33-vmhv-48xh?

3 open source packages ship an affected version, including ntru.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `ntru` | crates.io | From 0.0.0-0 | None |
| `ntru` | crates.io | From 0.4.3 to 0.5.6 | None |
| `ntru` | crates.io | From 0.4.3 to 0.5.6 | None |

## How do I fix GHSA-fq33-vmhv-48xh?

No fix has been published for GHSA-fq33-vmhv-48xh yet. Limit exposure of the affected software until one is available.

## Is GHSA-fq33-vmhv-48xh being exploited?

There is no known exploitation of GHSA-fq33-vmhv-48xh in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-fq33-vmhv-48xh and fix it if it is affected.

What it is: GHSA-fq33-vmhv-48xh is a memory corruption vulnerability in ntru, published on 22 Mar 2023. 
Exploitation: There is no known exploitation of GHSA-fq33-vmhv-48xh in the wild and no public exploit code.

Affected packages and fixed versions:
- ntru (crates.io): affected from 0.0.0-0; no fix listed
- ntru (crates.io): affected from 0.4.3 up to 0.5.6; no fix listed
- ntru (crates.io): affected from 0.4.3 up to 0.5.6; no fix listed

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-fq33-vmhv-48xh/ (Markdown: https://insights.sbomify.com/GHSA-fq33-vmhv-48xh/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-fq33-vmhv-48xh

---
From sbomify Insights: https://insights.sbomify.com/GHSA-fq33-vmhv-48xh/
Summaries are generated and may contain mistakes; the official description above is the record.
