-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
macOS 26 arm64: vec![None; N] with Option<NonZero<…>> can cause libc abort on free #150898
Copy link
Copy link
Closed
Closed
Copy link
Labels
C-bugCategory: This is a bug.Category: This is a bug.C-external-bugCategory: issue that is caused by bugs in software beyond our controlCategory: issue that is caused by bugs in software beyond our controlO-AArch64Armv8-A or later processors in AArch64 modeArmv8-A or later processors in AArch64 modeO-appleOperating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)O-macosOperating system: macOSOperating system: macOSP-highHigh priorityHigh priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.C-external-bugCategory: issue that is caused by bugs in software beyond our controlCategory: issue that is caused by bugs in software beyond our controlO-AArch64Armv8-A or later processors in AArch64 modeArmv8-A or later processors in AArch64 modeO-appleOperating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)O-macosOperating system: macOSOperating system: macOSP-highHigh priorityHigh priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Done
View all comments
On macOS Tahoe (arm64), using the
vec![T; N]initializer orstd::vec::from_elem(T, N)for certain data structure patterns can lead to a libc abort onfree(pointer being freed was not allocated).Affected pattern
The issue reproduces reliably with types involving niche optimization, in particular:
Option<(NonZero<u32>, u64, u64)>Using:
may cause the resulting allocation to be rejected by libc during
free.In contrast, constructing the same vector via:
does not reproduce the issue.
Environment sensitivity
The issue is highly sensitive to compiler and codegen settings and appears only under specific optimization configurations:
Observed behavior
Vec::from_elem/vec![T; N], the buffer may be filled with non-deterministic bit patterns (likely coming from padding / unused bytes in niche-optimizedOption<NonZero<...>>).xzm_free) treats the pointer as not allocated and aborts on free.Investigation notes
malloc_size/malloc_zone_from_ptr)Vec::extend_with),malloc_sizeandmalloc_zone_from_ptrreport the pointer as invalid (no zone, size = 0).I tried this code: https://github.com/venhelhardt/r92-memory-corruption
I expected to see this happen:
vec![T; N]/std::vec::from_elem(T, N)should always produce aVecthat can be safely dropped.Instead, this happened: On macOS Tahoe (arm64), initializing certain niche-optimized types with
vec![None; N]causes the allocation to be treated as invalid, leading to a libc abort onfree.Meta
rustc --version --verbose:Backtrace
Unable to reproduce on the latest macOS 26.4