CVE-2021-28877 in Standard Libraryinfo

Summary

by MITRE • 04/12/2021

In the standard library in Rust before 1.51.0, the Zip implementation calls __iterator_get_unchecked() for the same index more than once when nested. This bug can lead to a memory safety violation due to an unmet safety requirement for the TrustedRandomAccess trait.

If you want to get best quality of vulnerability data, you may have to visit VulDB.

Analysis

by VulDB Data Team • 05/21/2025

The vulnerability described in CVE-2021-28877 resides within the Rust standard library's implementation of the Zip iterator functionality, specifically affecting versions prior to 1.51.0. This issue manifests when Zip iterators are nested within each other, creating a scenario where the internal __iterator_get_unchecked() method is invoked multiple times for identical indices. The root cause stems from improper handling of iterator state management within the TrustedRandomAccess trait implementation, which governs how iterators interact with memory safety guarantees in Rust's ownership system. The TrustedRandomAccess trait requires that iterators maintain certain invariants regarding index access patterns, and the flawed Zip implementation violates these requirements through its nested iteration logic.

The technical flaw represents a memory safety violation that occurs due to the violation of safety contracts inherent in Rust's iterator system. When nested Zip iterators process elements, the __iterator_get_unchecked() function is called redundantly on the same index positions, potentially leading to undefined behavior through memory access violations. This vulnerability directly maps to CWE-129, which addresses improper handling of index values that can result in memory corruption. The issue exploits the underlying assumption that TrustedRandomAccess iterators maintain consistent access patterns and that __iterator_get_unchecked() can be safely called without additional bounds checking when indices are properly validated.

The operational impact of this vulnerability extends beyond simple memory corruption, as it can enable attackers to potentially execute arbitrary code or cause application crashes through controlled memory access patterns. In environments where Rust applications rely heavily on iterator-based data processing, particularly in systems handling untrusted input or performing complex data transformations, this vulnerability could be exploited to bypass memory safety guarantees that Rust is designed to enforce. The vulnerability affects the core iterator infrastructure, making it particularly dangerous as it can propagate through any code that utilizes Zip iterators, especially in nested scenarios common in functional programming patterns and data processing pipelines.

Mitigation strategies for CVE-2021-28877 primarily involve upgrading to Rust version 1.51.0 or later, where the Zip iterator implementation has been corrected to properly handle nested iteration scenarios. System administrators and developers should prioritize this upgrade across all affected environments, particularly in production systems where Rust is utilized for critical operations. Additionally, organizations should conduct thorough code reviews to identify any custom iterator implementations that might rely on similar patterns and ensure they properly implement TrustedRandomAccess trait requirements. The fix addresses the underlying safety contract violations by ensuring that __iterator_get_unchecked() calls maintain proper index consistency and that nested iterator operations do not result in duplicate index access patterns that could compromise memory safety. Security teams should also monitor for potential indirect exploitation vectors through third-party libraries that may have been compiled with affected Rust versions and could expose this vulnerability through their dependency chains.

Reservation

03/19/2021

Disclosure

04/12/2021

Moderation

accepted

CPE

ready

EPSS

0.01387

KEV

no

Activities

very low

Sources

Are you interested in using VulDB?

Download the whitepaper to learn more about our service!