{"id":"RUSTSEC-2026-0197","summary":"`Matrix{2,3,4}::swap_columns` can trigger undefined behavior for identical indices","details":"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`.","modified":"2026-07-03T13:45:04.208022006Z","published":"2026-03-11T12:00:00Z","database_specific":{"license":"CC0-1.0"},"references":[{"type":"PACKAGE","url":"https://crates.io/crates/cgmath"},{"type":"ADVISORY","url":"https://rustsec.org/advisories/RUSTSEC-2026-0197.html"},{"type":"REPORT","url":"https://github.com/rustgd/cgmath/issues/565"}],"affected":[{"package":{"name":"cgmath","ecosystem":"crates.io","purl":"pkg:cargo/cgmath"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0.0.0-0"}]}],"ecosystem_specific":{"affected_functions":null,"affects":{"os":[],"functions":["cgmath::Matrix2::swap_columns","cgmath::Matrix3::swap_columns","cgmath::Matrix4::swap_columns"],"arch":[]}},"database_specific":{"source":"https://github.com/rustsec/advisory-db/blob/osv/crates/RUSTSEC-2026-0197.json","cvss":null,"informational":"unsound","categories":["memory-corruption"]}}],"schema_version":"1.7.5"}