diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2023-02-12 18:42:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-12 18:42:35 +0200 |
commit | 5a83af4837c016d89378f9fa982141b34ff30a23 (patch) | |
tree | a05c144ce5dd8d239bdb0dd60d4312466e370cf0 /ext/ffi/repr.rs | |
parent | d4e5a295f2f9af1f815596656a185b11d7dabb29 (diff) |
perf(ext/ffi): Revert UTF-8 validity check from getCString (#17741)
Diffstat (limited to 'ext/ffi/repr.rs')
-rw-r--r-- | ext/ffi/repr.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/ext/ffi/repr.rs b/ext/ffi/repr.rs index db03479dc..c21b2b0f1 100644 --- a/ext/ffi/repr.rs +++ b/ext/ffi/repr.rs @@ -145,14 +145,13 @@ where let ptr = unsafe { ptr.add(offset) }; // SAFETY: Pointer is user provided. - let cstr = unsafe { CStr::from_ptr(ptr as *const c_char) } - .to_str() - .map_err(|_| type_error("Invalid CString pointer, not valid UTF-8"))?; - let value: v8::Local<v8::Value> = v8::String::new(scope, cstr) - .ok_or_else(|| { - type_error("Invalid CString pointer, string exceeds max length") - })? - .into(); + let cstr = unsafe { CStr::from_ptr(ptr as *const c_char) }.to_bytes(); + let value: v8::Local<v8::Value> = + v8::String::new_from_utf8(scope, cstr, v8::NewStringType::Normal) + .ok_or_else(|| { + type_error("Invalid CString pointer, string exceeds max length") + })? + .into(); Ok(value.into()) } |