Email me

Rust advisories / cgmath

UnsoundRUSTSEC-2026-0197 · cgmath

RUSTSEC-2026-0197: `Matrix{2,3,4}::swap_columns` can trigger undefined behavior for identical indices

Short answercgmath has an API that can cause undefined behaviour from safe code: `Matrix{2,3,4}::swap_columns` can trigger undefined behavior for identical indices. No fixed version yet.

Cratecgmath
TypeUnsound (memory-corruption)
Affected versionsEvery version.
Fixed innone
Severitynot scored
Published2026-03-11
Last changed2026-07-03
Also known asnone
Affected functionscgmath::Matrix2::swap_columns, cgmath::Matrix3::swap_columns, cgmath::Matrix4::swap_columns

What to do

  1. Find who pulls it in: cargo tree -i cgmath.
  2. Avoid the affected API (cgmath::Matrix2::swap_columns, cgmath::Matrix3::swap_columns, cgmath::Matrix4::swap_columns), or replace the crate.

Details from the advisory

The Matrix2::swap_columns, Matrix3::swap_columns, and Matrix4::swap_columns implementations call ptr::swap(&mut self[a], &mut self[b]).

When a == b, these safe APIs create two mutable references to the same matrix column and pass them to ptr::swap. This violates Rust's aliasing rules and can trigger undefined behavior. The issue can be reproduced from safe Rust by calling swap_columns with identical column indices, for example m.swap_columns(0, 0).

A minimal fix is to return early when the two column indices are equal before calling ptr::swap.

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.

Other advisories for cgmath

Full security history of cgmath

Up next

Same cratecgmath: security historyEvery advisory for this crate, and whether it is safe to use today.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