-
Notifications
You must be signed in to change notification settings - Fork 343
Open
Description
Hi, I am wondering whether this code might create an illegal string, which contains any non-utf8 value.
Lines 158 to 164 in 6b12ea1
pub fn source_url(&self) -> &str { | |
let mut len = 0; | |
unsafe { | |
let ptr = v8__CompiledWasmModule__SourceUrl(self.0, &mut len); | |
let bytes = std::slice::from_raw_parts(ptr as _, len); | |
std::str::from_utf8_unchecked(bytes) | |
} |
Based on the pointer passed by
v8__CompiledWasmModule__SourceUrl
Lines 3737 to 3741 in 6b12ea1
const char* v8__CompiledWasmModule__SourceUrl(v8::CompiledWasmModule* self, | |
size_t* length) { | |
const std::string& source_url = self->source_url(); | |
*length = source_url.size(); | |
return source_url.data(); |
As I know, string in C++ is not required to be utf8 only. Therefore, the function source_url
might incorrectly assume that the string should also be legal in Rust.
refer to the documentation (https://v8.github.io/api/head/classv8_1_1CompiledWasmModule.html), there is also no guarantee of utf8 encoding in the definition.
Metadata
Metadata
Assignees
Labels
No labels