Skip to content

Commit

Permalink
Fix crashes with invalid utf-8.
Browse files Browse the repository at this point in the history
According to the discussion in emacs bug#74922 it's possible that
emacs passes invalid strings to dynamic libraries.
  • Loading branch information
kurnevsky committed Dec 17, 2024
1 parent 126241a commit dd6fec5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ emacs-macros = { path = "emacs-macros", version = "0.17.0" }
rustc_version = "0.2.3"

[features]
default = []
default = [ "utf-8-validation" ]
utf-8-validation = []
lossy-integer-conversion = []
nonzero-integer-conversion = []
Expand Down
2 changes: 1 addition & 1 deletion src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl FromLisp<'_> for String {
#[cfg(feature = "utf-8-validation")]
fn from_lisp(value: Value<'_>) -> Result<Self> {
let bytes = value.env.string_bytes(value)?;
Ok(String::from_utf8(bytes).unwrap())
String::from_utf8(bytes).map_err(|e| e.into())
}
}

Expand Down

0 comments on commit dd6fec5

Please sign in to comment.