ffi: throw on allocation failure in toArrayBuffer() · nodejs/node@de073c5 · GitHub
Skip to content

Commit de073c5

Browse files
authored
ffi: throw on allocation failure in toArrayBuffer()
The copy path of toArrayBuffer() allocated its backing store with V8's default failure mode, so a large length aborted the process with a fatal out-of-memory error. toBuffer() throws a catchable ERR_MEMORY_ALLOCATION_FAILED for the same input. Allocate with kReturnNull and throw ERR_MEMORY_ALLOCATION_FAILED when the allocation fails. The memory is left uninitialized because memcpy() fills it right after. Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Assisted-by: claude:opus-5.5 PR-URL: #66406 Fixes: #66405 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent a7a9784 commit de073c5

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎src/ffi/data.cc‎

Lines changed: 11 additions & 2 deletions

‎test/ffi/test-ffi-memory.js‎

Lines changed: 11 additions & 0 deletions

0 commit comments

Comments
 (0)