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

- Severity: not scored yet
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Published: 2026-03-11T12:00:00.000Z
- Modified: 2026-07-03T13:45:04.208Z

## Description

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`.

(As written by RustSec Advisory Database.)

## Affected

- cgmath (crates.io): from 0.0.0-0

## References

- <https://crates.io/crates/cgmath> (package)
- <https://rustsec.org/advisories/RUSTSEC-2026-0197.html> (advisory)
- <https://github.com/rustgd/cgmath/issues/565> (report)

## Sources

- RustSec Advisory Database: [RUSTSEC-2026-0197](https://rustsec.org/advisories/RUSTSEC-2026-0197.html), CC0-1.0, modified 2026-07-03

---

Page: https://cve.day/RUSTSEC-2026-0197 · Whole record: https://cve.day/RUSTSEC-2026-0197.json · Rebuilt by cve.day 2026-11-25T22:56:43.378Z
