diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2022-06-29 18:00:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-29 20:30:29 +0530 |
commit | 3ad8bd85578146f1bb0ce61912b6d6e9991a43c7 (patch) | |
tree | db9316f470d09374c88b4a3bbb9a4f28bf441078 /ext/ffi/lib.rs | |
parent | 6743b3227b21d2814380253f8e8a0e2c116fb0f7 (diff) |
fix(ext/ffi): Empty buffers error with index out of bounds on FFI (#14997)
Diffstat (limited to 'ext/ffi/lib.rs')
-rw-r--r-- | ext/ffi/lib.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index a5fc6b756..ca02aca5b 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -810,12 +810,16 @@ where ) })? .get_backing_store(); - let pointer = &backing_store[byte_offset] as *const _ as *const u8; + let pointer = if byte_offset > 0 { + &backing_store[byte_offset..] as *const _ as *const u8 + } else { + &backing_store[..] as *const _ as *const u8 + }; ffi_args.push(NativeValue { pointer }); } else if let Ok(value) = v8::Local::<v8::ArrayBuffer>::try_from(value) { let backing_store = value.get_backing_store(); - let pointer = &backing_store as *const _ as *const u8; + let pointer = &backing_store[..] as *const _ as *const u8; ffi_args.push(NativeValue { pointer }); } else { return Err(type_error("Invalid FFI pointer type, expected null, BigInt, ArrayBuffer, or ArrayBufferView")); @@ -995,13 +999,17 @@ where ) })? .get_backing_store(); - let pointer = &backing_store[byte_offset] as *const _ as *const u8; + let pointer = if byte_offset > 0 { + &backing_store[byte_offset..] as *const _ as *const u8 + } else { + &backing_store[..] as *const _ as *const u8 + }; ffi_args.push(NativeValue { pointer }); } else if let Ok(value) = v8::Local::<v8::ArrayBuffer>::try_from(value) { let backing_store = value.get_backing_store(); - let pointer = &backing_store as *const _ as *const u8; + let pointer = &backing_store[..] as *const _ as *const u8; ffi_args.push(NativeValue { pointer }); } else { @@ -1367,11 +1375,15 @@ unsafe fn do_ffi_callback( .buffer(&mut scope) .expect("Unable to deserialize result parameter.") .get_backing_store(); - let pointer = &backing_store[byte_offset] as *const _ as *const u8; + let pointer = if byte_offset > 0 { + &backing_store[byte_offset..] as *const _ as *const u8 + } else { + &backing_store[..] as *const _ as *const u8 + }; *(result as *mut *const u8) = pointer; } else if let Ok(value) = v8::Local::<v8::ArrayBuffer>::try_from(value) { let backing_store = value.get_backing_store(); - let pointer = &backing_store as *const _ as *const u8; + let pointer = &backing_store[..] as *const _ as *const u8; *(result as *mut *const u8) = pointer; } else if let Ok(value) = v8::Local::<v8::BigInt>::try_from(value) { *(result as *mut u64) = value.u64_value().0; |