Skip to content

ffi: throw on allocation failure in toArrayBuffer() - #66406

Open
trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:ffi-toarraybuffer-allocation-failure
Open

trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:ffi-toarraybuffer-allocation-failure

Conversation

@trivikr

@trivikr trivikr commented Sep 30, 2026

Copy link
Copy Markdown
Member

Fixes: #66405

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.


Assisted-by: claude:opus-5.5

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Sep 30, 2026
@daeyeon daeyeon added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. ffi Issues and PRs related to experimental Foreign Function Interface support. labels Sep 30, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 30, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.39%. Comparing base (bd83a5c) to head (1d89180).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66406      +/-   ##
==========================================
- Coverage   90.39%   90.39%   -0.01%     
==========================================
  Files         792      792              
  Lines      275683   275688       +5     
  Branches    52854    52852       -2     
==========================================
  Hits       249216   249216              
+ Misses      16886    16883       -3     
- Partials     9581     9589       +8     
Files with missing lines Coverage Δ
src/ffi/data.cc 78.58% <100.00%> (+0.44%) ⬆️

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trivikr trivikr added resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. and removed resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. labels Sep 30, 2026
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
@trivikr
trivikr force-pushed the ffi-toarraybuffer-allocation-failure branch from a05e7ef to 1d89180 Compare September 30, 2026 14:26
@trivikr

This comment was marked as outdated.

@trivikr
trivikr requested review from addaleax and daeyeon September 30, 2026 14:27
@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 30, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 30, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. and removed commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue PRs queued for automated landing through the Commit Queue. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ffi: toArrayBuffer() aborts on allocation failure instead of throwing

5 participants