The Rust Foundation has published statistics indicating that out of 127,000 significant packages listed in the crates.io directory, over 24,000 (19.11%) utilize the keyword "unsafe" to enable features that allow unsafe memory operations in certain code blocks, such as pointer dereferencing, calling external functions, or modifying static variables. 34.35% of packages make direct calls to functions from other crate packages that employ the "unsafe" mode.
It is noted that in most cases, the use of the "unsafe" mode is due to calling code written in other languages or accessing libraries in C/C++. The crate package with the highest number of calls in "unsafe" mode is the windows package developed by Microsoft, which serves as a wrapper around the Windows API. This package has recorded 36 million downloads. Unsafe is also used in the most popular packages syn (470 million downloads), proc-macro2 (354 million downloads), and libc (345 million downloads).
To identify issues in code executed in "unsafe" mode, a project is developing the Miri interpreter, which allows for the detection of accesses outside buffer boundaries, use of memory after it has been freed, incorrect use of uninitialized data, violation of basic type invariants (e.g., bool values not being 0 or 1), breaches of ownership rules, race conditions, and memory leaks.
Source: opennet.ru
