{"id":"RUSTSEC-2026-0197","aliases":["RUSTSEC-2026-0197"],"related":[],"kind":"vulnerability","state":"published","title":"`Matrix{2,3,4}::swap_columns` can trigger undefined behavior for identical indices","summary":"The `Matrix2::swap_columns`, `Matrix3::swap_columns`, and `Matrix4::swap_columns`\nimplementations call `ptr::swap(&mut self[a], &mut self[b])`.\n\nWhen `a == b`, these safe APIs create two mutable references to the same matrix\ncolumn and pass them to `ptr::swap`. This violates Rust's aliasing rules and can\ntrigger undefined behavior. The issue can be reproduced from safe Rust by calling\n`swap_columns` with identical column indices, for example `m.swap_columns(0, 0)`.\n\nA minimal fix is to return early when the two column indices are equal before\ncalling `ptr::swap`.","summaryFormat":"markdown","summarySource":"rustsec","descriptions":[{"lang":"en","text":"The `Matrix2::swap_columns`, `Matrix3::swap_columns`, and `Matrix4::swap_columns`\nimplementations call `ptr::swap(&mut self[a], &mut self[b])`.\n\nWhen `a == b`, these safe APIs create two mutable references to the same matrix\ncolumn and pass them to `ptr::swap`. This violates Rust's aliasing rules and can\ntrigger undefined behavior. The issue can be reproduced from safe Rust by calling\n`swap_columns` with identical column indices, for example `m.swap_columns(0, 0)`.\n\nA minimal fix is to return early when the two column indices are equal before\ncalling `ptr::swap`.","format":"markdown","source":"rustsec"}],"published":"2026-03-11T12:00:00.000Z","modified":"2026-07-03T13:45:04.208Z","severities":[],"cwes":[],"affected":[{"ranges":[{"type":"semver","introduced":"0.0.0-0","status":"affected"}],"ecosystem":"crates.io","package":"cgmath","purl":"pkg:cargo/cgmath","source":"rustsec"}],"references":[{"url":"https://crates.io/crates/cgmath","tags":["package"],"sources":["rustsec"]},{"url":"https://rustsec.org/advisories/RUSTSEC-2026-0197.html","tags":["advisory"],"sources":["rustsec"]},{"url":"https://github.com/rustgd/cgmath/issues/565","tags":["report"],"sources":["rustsec"]}],"credits":[],"sources":[{"source":"rustsec","name":"RustSec Advisory Database","id":"RUSTSEC-2026-0197","url":"https://rustsec.org/advisories/RUSTSEC-2026-0197.html","licence":"CC0-1.0","modified":"2026-07-03T13:45:04.208Z"}],"updatedAt":"2026-11-25T22:56:43.378Z"}