Email me

Rust advisories / wasapi

UnsoundRUSTSEC-2026-0332 · wasapi

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

Short answerwasapi has an API that can cause undefined behaviour from safe code: `WaveFormat::parse` reads past the end of a `&WAVEFORMATEX`. Fixed in 0.25.0.

Cratewasapi
TypeUnsound (memory-exposure)
Affected versionsFrom 0.20.0 before 0.25.0.
Fixed in0.25.0
Severitynot scored
Published2026-09-08
Last changed2026-10-07
Also known asnone
Affected functionswasapi::WaveFormat::parse

What to do

  1. See which version you have: cargo tree -i wasapi (it also shows which of your dependencies pulls it in).
  2. Update within your version requirement: cargo update -p wasapi. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for example wasapi = "0.25.0") or update the dependency that pulls it in.
  3. Check again with cargo audit, or paste your Cargo.lock into our Cargo.toml checker.

Details from the advisory

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:

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.

References

From the RustSec Advisory Database (CC0-1.0) via the OSV export, downloaded Oct 24, 2026. Severity score computed from the published CVSS vector.

Up next

Are you affected?Check your whole dependency treePaste Cargo.lock: every advisory, for your exact versions.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ