Engineers from Meta* published a report on the processing of components of the WhatsApp messenger using the Rust language. The report details the creation of a new version of the wamedia library, originally written in C++, which is used in WhatsApp for sending and processing multimedia files in MP4 format.
The decision to rework the library was made after errors were discovered in wamedia when processing improperly formatted MP4 files. While similar errors were fixed and checks were added to ensure file correctness, the library presented a potential security risk due to unidentified errors and its use in automatically processing sent data. An unpatched vulnerability in wamedia could allow malicious users to execute code by sending specially formatted media data.
Instead of gradually rewriting wamedia, the engineers developed a new version of the library in Rust, alongside the original C++ version. Ultimately, approximately 160 thousand lines of C++ code were replaced with 90 thousand lines of Rust code.
Challenges encountered during the transition to Rust included an increase in executable file size due to the integration of the standard Rust library, as well as the need to adapt the build system across all supported platforms. Despite this, the Rust implementation showed improvements in performance and memory consumption compared to the C++ version.
The Rust version of WhatsApp has been rolled out to users on Android, iOS, macOS, Web, wearable devices, and other platforms. Meta suggests that this successful implementation demonstrates the potential for using Rust on a global scale.
Meta highlights that a significant number of vulnerabilities in their products stem from memory-related issues in C and C++ code. To address this, the company is advocating for the use of memory-safe languages for new code, minimizing attack surfaces in design, and investing in tools to enhance the security of existing C and C++ code.