Security mailing lists by PureSourceCode

RUSTSEC-2020-0161

MEDIUM

`array!` macro is unsound in presence of traits that implement methods it calls internally

Affected versions of this crate called some methods using auto-ref. The affected code looked like this.

let mut arr = $crate::__core::mem::MaybeUninit::uninit();
let mut vec = $crate::__ArrayVec::<T>::new(arr.as_mut_ptr() as *mut T);

In this case, the problem is that as_mut_ptr is a method of &mut MaybeUninit, not MaybeUninit. This made it possible for traits to hijack the method calls in order to cause unsoundness.

trait AsMutPtr<T> {
    fn as_mut_ptr(&self) -> *mut T;
}
impl<T> AsMutPtr<T> for std::mem::MaybeUninit<T> {
    fn as_mut_ptr(&self) -> *mut T {
        std::ptr::null_mut()
    }
}
array![0; 1];

The flaw was corrected by explicitly referencing variables in macro body in order to avoid auto-ref.

Published
7 May 2020
Last modified
8 Nov 2023
Also known as
GHSA-83gg-pwxf-jr89
Sources
OSV GHSA-83gg-pwxf-jr89JSONOSVJSON

Affected

SourceVendor / ecosystemProduct / packageAffected versionsFixed in
OSV crates.io array-macro >= 0.1.2, < 1.0.5 1.0.5

References

History

  • 25 Nov 2026 20:14 UTC · OSV: first stored (published 7 May 2020)
  • 25 Nov 2026 20:14 UTC · OSV: first stored (published 16 Jun 2022)
An unhandled error has occurred. Reload ×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.