Out-of-Bounds Affecting ascii package, versions <0.9.3


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-RUST-ASCII-3332735
  • published27 Feb 2023
  • disclosed25 Feb 2023
  • creditTorbjørn Birch Moltu

Introduced: 25 Feb 2023

CVE NOT AVAILABLE CWE-119  (opens in a new tab)

How to fix?

Upgrade ascii to version 0.9.3 or higher.

Overview

ascii is a library that provides ASCII-only string and character types, equivalent to the char, str and String types in the standard library.

Affected versions of this package are vulnerable to Out-of-Bounds due to insecure implementation of From<&mut AsciiStr> for &mut [u8] and &mut str, which allows writing non-ASCII values to an AsciiStr which when read out as an AsciiChar will produce values outside the valid niche.

PoC

let mut buf = [0u8; 1];
let ascii = buf.as_mut_ascii_str().unwrap();
let byte_view = <&mut[u8] as From<&mut AsciiStr>>::from(ascii);
let arr = [0b11011101u8; 128];
byte_view[0] = 180;
assert_ne!(arr[ascii[0] as u8 as usize], 0b11011101);

CVSS Scores

version 3.1