You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A-UnicodeArea: UnicodeC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.
It's possible to use String::replace_range to create invalid strings containing broken Unicode. This happens because replace_range checks range bounds twice - first time to check parameter validity and second time for actually doing the splice.
use std::cell::Cell;use std::ops::{Bound,RangeBounds};use std::str;structEvilRange(Cell<bool>);implRangeBounds<usize>forEvilRange{fnstart_bound(&self) -> Bound<&usize>{Bound::Included(ifself.0.get(){&1}else{self.0.set(true);&0})}fnend_bound(&self) -> Bound<&usize>{Bound::Unbounded}}fnmain(){letmut s = String::from("🦀");
s.replace_range(EvilRange(Cell::new(false)),"");println!("{:?}",str::from_utf8(s.as_bytes()));}
This will print Utf8Error showing that a string is not valid UTF-8.
The text was updated successfully, but these errors were encountered:
Mark-Simulacrum
added
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
labels
Jan 17, 2021
A-UnicodeArea: UnicodeC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.
It's possible to use
String::replace_range
to create invalid strings containing broken Unicode. This happens becausereplace_range
checks range bounds twice - first time to check parameter validity and second time for actually doing the splice.This will print
Utf8Error
showing that a string is not valid UTF-8.The text was updated successfully, but these errors were encountered: