Skip to content
Closed
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions src/decoder/sorted_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ pub fn read_sorted_set<R: Read>(
255 => f64::NEG_INFINITY,
_ => {
let tmp = read_exact(input, score_length as usize)?;
unsafe { str::from_utf8_unchecked(&tmp) }
str::from_utf8(&tmp)
.map_err(|_| RdbError::ParsingError {
context: "read_sorted_set",
message: "Invalid UTF-8 in score".to_string(),
})?
.parse::<f64>()
.unwrap()
.map_err(|_| RdbError::ParsingError {
context: "read_sorted_set",
message: "Invalid score format".to_string(),
})?
}
}
};
Expand Down Expand Up @@ -105,7 +112,14 @@ pub fn read_sorted_set_listpack<R: Read>(
let member = read_list_pack_entry_as_string(&mut reader)?;
let score_str = read_list_pack_entry_as_string(&mut reader)?;

let score = unsafe { str::from_utf8_unchecked(&score_str) }
let score = str::from_utf8(&score_str)
.map_err(|_| RdbError::ParsingError {
context: "read_sorted_set_listpack",
message: format!(
"Failed to parse score: {:?}",
String::from_utf8_lossy(&score_str)
),
})?
.parse::<f64>()
.map_err(|_| RdbError::ParsingError {
context: "read_sorted_set_listpack",
Expand Down
6 changes: 4 additions & 2 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ impl Filter for Simple {
match self.keys.clone() {
None => true,
Some(re) => {
let key = unsafe { str::from_utf8_unchecked(key) };
re.is_match(key)
match str::from_utf8(key) {
Ok(key_str) => re.is_match(key_str),
Err(_) => false
}
}
}
}
Expand Down
Loading