CVE-2021-29942
Description
The swap_index function in the Rust reorder crate (≤2021-02-24) can return uninitialized memory when an iterator provides an incorrect len(), leading to memory corruption.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
The `swap_index` function in the Rust `reorder` crate (≤2021-02-24) can return uninitialized memory when an iterator provides an incorrect `len()`, leading to memory corruption.
The swap_index function in the reorder crate for Rust trusts the len() method of an ExactSizeIterator to allocate a Vec and set its length via unsafe code. If the iterator returns a len() larger than the actual number of elements, the function will expose uninitialized memory when the Vec is returned [1][3]. This violates the safety guarantees documented for ExactSizeIterator::len(), which states that the value must not be trusted for bounds checks in unsafe code [3].
An attacker can exploit this by providing a crafted iterator that implements ExactSizeIterator with an inflated len() but yields fewer items. The function does not validate the iterator's length against the actual number of elements, allowing an attacker to trigger out-of-bounds writes or reads of uninitialized memory. The attack requires no authentication and can be performed over a network, as reflected in the CVSS vector (AV:N/AC:L/PR:N/UI:N) [1].
Successful exploitation could lead to memory corruption, potentially resulting in information disclosure (reading uninitialized memory) or denial of service (due to undefined behavior). The vulnerability is rated HIGH with a CVSS score of 7.3 [1].
The issue was reported on February 24, 2021, and patched in version 1.1.0 of the reorder crate. Users are advised to update to the latest version to mitigate the risk [1].
AI Insight generated on May 21, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
reordercrates.io | < 1.1.0 | 1.1.0 |
Affected products
2- Rust/reorderdescription
Patches
0No patches discovered yet.
Vulnerability mechanics
AI mechanics synthesis has not run for this CVE yet.
References
4- github.com/advisories/GHSA-jpwg-6gf5-5vh9ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2021-29942ghsaADVISORY
- github.com/tiby312/reorder/issues/1ghsaWEB
- rustsec.org/advisories/RUSTSEC-2021-0050.htmlghsax_refsource_MISCWEB
News mentions
0No linked articles in our index yet.