{"id":"GHSA-83gg-pwxf-jr89","aliases":["RUSTSEC-2020-0161"],"status":"published","title":"`array!` macro is unsound in presence of traits that implement methods it calls internally","description":"Affected versions of this crate called some methods using auto-ref. The affected code looked like this.\n\n```rust\nlet mut arr = $crate::__core::mem::MaybeUninit::uninit();\nlet mut vec = $crate::__ArrayVec::\u003cT\u003e::new(arr.as_mut_ptr() as *mut T);\n```\n\nIn this case, the problem is that `as_mut_ptr` is a method of `\u0026mut MaybeUninit`, not `MaybeUninit`. This made it possible for traits to hijack the method calls in order to cause unsoundness.\n\n```rust\ntrait AsMutPtr\u003cT\u003e {\n    fn as_mut_ptr(\u0026self) -\u003e *mut T;\n}\nimpl\u003cT\u003e AsMutPtr\u003cT\u003e for std::mem::MaybeUninit\u003cT\u003e {\n    fn as_mut_ptr(\u0026self) -\u003e *mut T {\n        std::ptr::null_mut()\n    }\n}\narray![0; 1];\n```\n\nThe flaw was corrected by explicitly referencing variables in macro body in order to avoid auto-ref.","facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":true},"published":"2020-05-07T12:00:00Z","modified":"2023-11-08T04:17:08Z","fixes":[{"ecosystem":"crates.io","package":"array-macro","fixed_in":["1.0.5"],"sources":["ghsa","osv"]}],"affected":[{"source":"ghsa","ecosystem":"crates.io","package":"array-macro","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0.1.2"},{"fixed":"1.0.5"}]}]},{"source":"osv","ecosystem":"crates.io","package":"array-macro","ranges":[{"type":"SEMVER","events":[{"introduced":"0.1.2"},{"fixed":"1.0.5"}]}]},{"source":"osv","ecosystem":"crates.io","package":"array-macro","ranges":[{"type":"SEMVER","events":[{"introduced":"0.1.2"},{"fixed":"1.0.5"}]}]}],"references":[{"url":"https://github.com/rustsec/advisory-db/blob/main/crates/array-macro/RUSTSEC-2020-0161.md","tags":["web"]},{"url":"https://rustsec.org/advisories/RUSTSEC-2020-0161.html","tags":["web","advisory"]},{"url":"https://github.com/xfix/array-macro/commit/01940637dd8f3bfeeee3faf9639fa9ae52f19f4d","tags":["web"]},{"url":"https://gitlab.com/KonradBorowski/array-macro/-/commit/01940637dd8f3bfeeee3faf9639fa9ae52f19f4d","tags":["web"]},{"url":"https://github.com/advisories/GHSA-83gg-pwxf-jr89"},{"url":"https://github.com/xfix/array-macro","tags":["package"]},{"url":"https://crates.io/crates/array-macro","tags":["package"]}],"sources":{"ghsa":[{"id":"GHSA-83gg-pwxf-jr89","title":"`array!` macro is unsound in presence of traits that implement methods it calls internally","description":"Affected versions of this crate called some methods using auto-ref. The affected code looked like this.\n\n```rust\nlet mut arr = $crate::__core::mem::MaybeUninit::uninit();\nlet mut vec = $crate::__ArrayVec::\u003cT\u003e::new(arr.as_mut_ptr() as *mut T);\n```\n\nIn this case, the problem is that `as_mut_ptr` is a method of `\u0026mut MaybeUninit`, not `MaybeUninit`. This made it possible for traits to hijack the method calls in order to cause unsoundness.\n\n```rust\ntrait AsMutPtr\u003cT\u003e {\n    fn as_mut_ptr(\u0026self) -\u003e *mut T;\n}\nimpl\u003cT\u003e AsMutPtr\u003cT\u003e for std::mem::MaybeUninit\u003cT\u003e {\n    fn as_mut_ptr(\u0026self) -\u003e *mut T {\n        std::ptr::null_mut()\n    }\n}\narray![0; 1];\n```\n\nThe flaw was corrected by explicitly referencing variables in macro body in order to avoid auto-ref.\n","status":"published","published":"2022-06-16T23:40:19Z","modified":"2023-06-13T16:35:34Z","updated_at":"2026-11-02T14:36:53.103029Z"}],"osv":[{"id":"GHSA-83gg-pwxf-jr89","title":"`array!` macro is unsound in presence of traits that implement methods it calls internally","description":"Affected versions of this crate called some methods using auto-ref. The affected code looked like this.\n\n```rust\nlet mut arr = $crate::__core::mem::MaybeUninit::uninit();\nlet mut vec = $crate::__ArrayVec::\u003cT\u003e::new(arr.as_mut_ptr() as *mut T);\n```\n\nIn this case, the problem is that `as_mut_ptr` is a method of `\u0026mut MaybeUninit`, not `MaybeUninit`. This made it possible for traits to hijack the method calls in order to cause unsoundness.\n\n```rust\ntrait AsMutPtr\u003cT\u003e {\n    fn as_mut_ptr(\u0026self) -\u003e *mut T;\n}\nimpl\u003cT\u003e AsMutPtr\u003cT\u003e for std::mem::MaybeUninit\u003cT\u003e {\n    fn as_mut_ptr(\u0026self) -\u003e *mut T {\n        std::ptr::null_mut()\n    }\n}\narray![0; 1];\n```\n\nThe flaw was corrected by explicitly referencing variables in macro body in order to avoid auto-ref.\n","status":"published","published":"2022-06-16T23:40:19Z","modified":"2023-11-08T04:17:08.031225Z","updated_at":"2026-11-02T15:46:41.732368Z"},{"id":"RUSTSEC-2020-0161","title":"`array!` macro is unsound in presence of traits that implement methods it calls internally","description":"Affected versions of this crate called some methods using auto-ref. The affected code looked like this.\n\n```rust\nlet mut arr = $crate::__core::mem::MaybeUninit::uninit();\nlet mut vec = $crate::__ArrayVec::\u003cT\u003e::new(arr.as_mut_ptr() as *mut T);\n```\n\nIn this case, the problem is that `as_mut_ptr` is a method of `\u0026mut MaybeUninit`, not `MaybeUninit`. This made it possible for traits to hijack the method calls in order to cause unsoundness.\n\n```rust\ntrait AsMutPtr\u003cT\u003e {\n    fn as_mut_ptr(\u0026self) -\u003e *mut T;\n}\nimpl\u003cT\u003e AsMutPtr\u003cT\u003e for std::mem::MaybeUninit\u003cT\u003e {\n    fn as_mut_ptr(\u0026self) -\u003e *mut T {\n        std::ptr::null_mut()\n    }\n}\narray![0; 1];\n```\n\nThe flaw was corrected by explicitly referencing variables in macro body in order to avoid auto-ref.","status":"published","published":"2020-05-07T12:00:00Z","modified":"2023-11-08T04:17:08.031225Z","updated_at":"2026-11-02T15:53:39.492624Z"}]}}
