Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add information about unsoundness issue in anstream #2075

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions crates/anstream/RUSTSEC-0000-0000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
```toml
[advisory]
id = "RUSTSEC-0000-0000"
package = "anstream"
date = "2024-09-08"
url = "https://github.com/rust-cli/anstyle/issues/156"
informational = "unsound"

[affected]
functions = { "anstream::adapter::strip_str" = ["< 0.6.8"] }

[versions]
patched = [">= 0.6.8"]

```

# Unsoundness in anstream

When given a valid UTF8 string "ö\x1b😀", the function in
crates/anstream/src/adapter/strip.rs will be confused. The UTF8
bytes are \xc3\xb6 then \x1b then \xf0\x9f\x98\x80.

When looping over "non-printable bytes" \x1b\xf0 will be
considered as some non-printable sequence.

This will produce a broken str from the incorrectly segmented
bytes via str::from_utf8_unchecked, and that should never happen.

Full credit goes to @Ralith who reviewed this code and
asked @burakemir to follow up.