Conversation
Fixes an issue where on 32-bit systems, the Source struct only reserves 3 u32 spaces for v8::ScriptCompiler::CompilationDetails (asserted as 3 u64 in binding.cc:67 "CompilationDetails size mismatch". Previously resulted in buffer overflow when Source::new is called as Rust doesn't allocate enough space before passing the memory to v8__ScriptCompiler__Source__CONSTRUCT for initialisation
|
Thanks for the detailed writeup — the analysis checks out. I verified the layouts against On armv7 the C++ On 64-bit targets Two requests:
// v8::ScriptCompiler::CompilationDetails: InMemoryCacheResult + 2 × int64_t.
// Must be u64, not usize — on 32-bit targets usize would undersize and
// under-align this struct, and the C++ constructor writes past the end.
_compilation_details: [u64; 3],
One caveat for the record: i686 Linux is still mismatched, since the i386 SysV ABI gives |
Hello,
While building rusty_v8 for 32-bit ARMv7 (armv7-unknown-linux-gnueabi), I might have stumbled into a stack buffer overflow in
ScriptCompiler::Source. My best guess is that the Rust struct doesn't match the C++ layout on 32-bit platforms. Happy to be corrected.The
ScriptCompiler::SourceRust struct ends in_compilation_details: [usize; 3], however the C++v8::ScriptCompiler::CompilationDetailsexpectssizeof(int64_t) * 3, as binding.cc itself asserts ("CompilationDetails size mismatch").rusty_v8/src/script_compiler.rs
Lines 65 to 80 in 8149304
rusty_v8/src/binding.cc
Lines 66 to 68 in 8149304
Thus, when
Source::new/new_with_cached_dataallocates aMaybeUninit::<Self>and passes it tov8__ScriptCompiler__Source__CONSTRUCT, the C++ function writes past the end of the Rust allocation.rusty_v8/src/script_compiler.rs
Lines 145 to 161 in 8149304
My fix is to change the
_compilation_detailsfield to be[u64; 3]regardless of which platform it's built for. I understand 32-bit isn't a supported/CI target so feel free to WONTFIX this.Thanks for taking a look!