Skip to content

Commit

Permalink
zv(fix): Fix FilePath deserialization
Browse files Browse the repository at this point in the history
Fix FilePath deserialization by replacing `from_utf8_lossy` to the `unsafe`
operation `from_utf8_unchecked` to validly decode all possible valid
paths.
  • Loading branch information
yassinebenarbia committed Sep 24, 2024
1 parent bece9a9 commit 8091305
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions zvariant/src/file_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ impl<'de> Deserialize<'de> for FilePath<'de> {
where
E: de::Error,
{
Ok(FilePath::from(
PathBuf::from(String::from_utf8_lossy(v).into_owned())
))
Ok(FilePath::from(PathBuf::from(
// SAFETY: File path do not necessarily contain only a sequence
// of UTF-8 characters, thus it's safe to assume that the path *contains*
// a non-vaalid UTF-8 characters, hence the `unsafe` block.
unsafe{
String::from_utf8_unchecked(v.to_vec())
}
)))
}
}
let visitor = FilePathVisitor;
Expand Down

0 comments on commit 8091305

Please sign in to comment.