{"id":"RUSTSEC-2026-0197","aliases":[],"status":"published","title":"`Matrix{2,3,4}::swap_columns` can trigger undefined behavior for identical indices","description":"The `Matrix2::swap_columns`, `Matrix3::swap_columns`, and `Matrix4::swap_columns`\nimplementations call `ptr::swap(\u0026mut self[a], \u0026mut 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`.","facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":false},"published":"2026-03-11T12:00:00Z","modified":"2026-07-03T13:45:04Z","affected":[{"source":"osv","ecosystem":"crates.io","package":"cgmath","ranges":[{"type":"SEMVER","events":[{"introduced":"0.0.0-0"}]}]}],"references":[{"url":"https://crates.io/crates/cgmath","tags":["package"]},{"url":"https://rustsec.org/advisories/RUSTSEC-2026-0197.html","tags":["advisory"]},{"url":"https://github.com/rustgd/cgmath/issues/565","tags":["report"]}],"sources":{"osv":[{"id":"RUSTSEC-2026-0197","title":"`Matrix{2,3,4}::swap_columns` can trigger undefined behavior for identical indices","description":"The `Matrix2::swap_columns`, `Matrix3::swap_columns`, and `Matrix4::swap_columns`\nimplementations call `ptr::swap(\u0026mut self[a], \u0026mut 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`.","status":"published","published":"2026-03-11T12:00:00Z","modified":"2026-07-03T13:45:04.208022006Z","updated_at":"2026-11-02T15:53:40.430679Z"}]}}
