mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
Avoid panic in sanitise_name()
.truncate() is not safe because it panics if string length does not lie on character boundary. We convert the string to characters and take first n character instead.
This commit is contained in:
committed by
Floris Bruynooghe
parent
ebab893330
commit
bf3eab453c
13
src/blob.rs
13
src/blob.rs
@@ -322,13 +322,12 @@ impl<'a> BlobObject<'a> {
|
|||||||
|
|
||||||
let clean = sanitize_filename::sanitize_with_options(name, opts);
|
let clean = sanitize_filename::sanitize_with_options(name, opts);
|
||||||
let mut iter = clean.splitn(2, '.');
|
let mut iter = clean.splitn(2, '.');
|
||||||
let mut stem = iter.next().unwrap_or_default().to_string();
|
let stem: String = iter.next().unwrap_or_default().chars().take(64).collect();
|
||||||
let mut ext = iter.next().unwrap_or_default().to_string();
|
let ext: String = iter.next().unwrap_or_default().chars().take(32).collect();
|
||||||
stem.truncate(64);
|
if ext.is_empty() {
|
||||||
ext.truncate(32);
|
(stem, "".to_string())
|
||||||
match ext.len() {
|
} else {
|
||||||
0 => (stem, "".to_string()),
|
(stem, format!(".{}", ext).to_lowercase())
|
||||||
_ => (stem, format!(".{}", ext).to_lowercase()),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user