# RUSTSEC-2026-0332: `WaveFormat::parse` reads past the end of a `&WAVEFORMATEX`

> A Rust library allows out-of-bounds memory reads when parsing specific audio format headers, potentially leaking sensitive data.

- **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:** 8 Sep 2026

## What is RUSTSEC-2026-0332?

RUSTSEC-2026-0332 is a memory corruption vulnerability in wasapi, published on 8 Sep 2026. 

### Official description

`WaveFormat::parse` is a safe function that takes a `&WAVEFORMATEX`, which is
only valid for reads of `size_of::<WAVEFORMATEX>()` (18) bytes. When the header
has `wFormatTag == WAVE_FORMAT_EXTENSIBLE` and `cbSize >= 22`, the function
reinterprets the reference as a `WAVEFORMATEXTENSIBLE` and reads 40 bytes.
Nothing in the signature guarantees that the header sits at the start of a
larger buffer, so safe code can trigger an out-of-bounds read:

```rust
use wasapi::WaveFormat;
use windows::Win32::Media::Audio::WAVEFORMATEX;
use windows::Win32::Media::KernelStreaming::WAVE_FORMAT_EXTENSIBLE;

let header = WAVEFORMATEX {
    wFormatTag: WAVE_FORMAT_EXTENSIBLE as u16,
    nChannels: 2,
    nSamplesPerSec: 48000,
    nAvgBytesPerSec: 384000,
    nBlockAlign: 8,
    wBitsPerSample: 32,
    cbSize: 22,
};
// Reads 22 bytes past the end of `header`.
let _ = WaveFormat::parse(&header);
```

A more likely way to hit this is to copy the header out of a format pointer
returned by WASAPI (`let fmt = unsafe { *ptr };`) and pass `&fmt`. The copy
keeps `cbSize`, but not the 22 bytes that follow it. The bytes read past the
end are returned as the channel mask and subformat of the parsed format.

The flaw was corrected in commit `2562db7`, released in 0.25.0. `parse` is now
an `unsafe fn` that takes a `*const WAVEFORMATEX`, and the caller must
guarantee that the pointer is valid for reads of
`size_of::<WAVEFORMATEX>() + cbSize` bytes. `WaveFormat::parse_from_blob_bytes`
(available since 0.23.0) is the safe alternative and checks the slice length
against `cbSize`.

## Which versions are affected by RUSTSEC-2026-0332?

1 open source package ship an affected version, including wasapi.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `wasapi` | crates.io | From 0.20.0 | 0.25.0 |

## How do I fix RUSTSEC-2026-0332?

Upgrade wasapi to 0.25.0 or later.

## Is RUSTSEC-2026-0332 being exploited?

There is no known exploitation of RUSTSEC-2026-0332 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for RUSTSEC-2026-0332 and fix it if it is affected.

What it is: RUSTSEC-2026-0332 is a memory corruption vulnerability in wasapi, published on 8 Sep 2026. 
Exploitation: There is no known exploitation of RUSTSEC-2026-0332 in the wild and no public exploit code.

Affected packages and fixed versions:
- wasapi (crates.io): affected from 0.20.0; fixed in 0.25.0

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/RUSTSEC-2026-0332/ (Markdown: https://insights.sbomify.com/RUSTSEC-2026-0332/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/RUSTSEC-2026-0332

---
From sbomify Insights: https://insights.sbomify.com/RUSTSEC-2026-0332/
Summaries are generated and may contain mistakes; the official description above is the record.
