Email me

Rust advisories / fruity

Vulnerability HighRUSTSEC-2021-0123 · fruity

RUSTSEC-2021-0123: Converting `NSString` to a String Truncates at Null Bytes

Short answerA security vulnerability in the fruity crate: Converting `NSString` to a String Truncates at Null Bytes. GitHub rates it High. Fixed in 0.3.0: update to a fixed version.

Cratefruity
TypeVulnerability
Affected versionsFrom 0.1.0 before 0.3.0.
Fixed in0.3.0
SeverityHigh (GitHub rating)
Published2021-11-14
Last changed2023-11-08
Also known asCVE-2021-43620, GHSA-h352-g5vw-3926
Affected functionsfruity::foundation::NSString::to_str, fruity::foundation::NSString::to_str_with_nul, fruity::foundation::NSString::to_string, fruity::foundation::NSString::to_string_with_nul

What to do

  1. See which version you have: cargo tree -i fruity (it also shows which of your dependencies pulls it in).
  2. Update within your version requirement: cargo update -p fruity. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for example fruity = "0.3.0") or update the dependency that pulls it in.
  3. Check again with cargo audit, or paste your Cargo.lock into our Cargo.toml checker.

Details from the advisory

Methods of NSString for conversion to a string may return a partial result. Since they call CStr::from_ptr on a pointer to the string buffer, the string is terminated at the first null byte, which might not be the end of the string.

In addition to the vulnerable functions listed for this issue, the implementations of Display, PartialEq, PartialOrd, and ToString for NSString are also affected, since they call those functions.

Impact

Since NSString is commonly used as the type for paths by the Foundation framework, null byte truncation might allow for easily bypassing file extension checks. For example, if a file name is provided by a user and validated to have one of a specific set of extensions, with validation taking place before truncation, an attacker can add an accepted extension after a null byte (e.g., file.exe\0.txt). After truncation, the file name used by the application would be file.exe.

It would be better to generate unique names for files, instead of using user-provided names, but not all applications take this approach.

Example:

let string = NSString::from_str("null\0byte");
println!("{}", string);

That example only prints the string "null".

References

From the RustSec Advisory Database (CC0-1.0) via the OSV export, downloaded Oct 24, 2026. Severity score computed from the published CVSS vector.

Up next

Are you affected?Check your whole dependency treePaste Cargo.lock: every advisory, for your exact versions.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ