ffi: validate fast pointer BigInt argument ranges · nodejs/node@6f9e084 · GitHub
Skip to content

Commit 6f9e084

Browse files
trivikraduh95
authored andcommitted
ffi: validate fast pointer BigInt argument ranges
Optimized V8 fast API calls truncate out-of-range pointer BigInts. Validate them against uintptrMax before invoking the raw function so optimized calls match the generic and shared-buffer paths. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol PR-URL: #65032 Fixes: #65031 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 3e50a2f commit 6f9e084

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

lib/internal/ffi/fast-api.js

Lines changed: 11 additions & 0 deletions

src/node_ffi.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,9 +1341,9 @@ static void Initialize(Local<Object> target,
13411341
Boolean::New(isolate, CHAR_MIN < 0))
13421342
.Check();
13431343

1344-
// The shared-buffer fast path uses `uintptrMax` to reject pointer BigInts
1345-
// that would otherwise be silently truncated by `ReadFFIArgFromBuffer`'s
1346-
// `memcpy(..., type->size, ...)` on 32-bit platforms. The slow path
1344+
// The JavaScript fast paths use `uintptrMax` to reject pointer BigInts that
1345+
// would otherwise be silently truncated by V8 or, on 32-bit platforms, by
1346+
// `ReadFFIArgFromBuffer`'s `memcpy(..., type->size, ...)`. The slow path
13471347
// rejects the same values through `ToFFIArgument`.
13481348
target
13491349
->Set(context,

test/ffi/test-ffi-fast-integer-validation.js

Lines changed: 31 additions & 0 deletions

0 commit comments

Comments
 (0)