]> git.kaiwu.me - njs.git/commit
Fixed Buffer allocation length checks
authorDmitry Volyntsev <xeioex@nginx.com>
Sat, 23 May 2026 01:18:39 +0000 (18:18 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 26 May 2026 21:45:24 +0000 (14:45 -0700)
commit759d713b0f19f744de426f7578b10ace7e2204a4
tree4e6880b79e557f51b79175d193c12ff9ed4172b1
parent963e860b1e6046c383e7951ec976d13419d8b86a
Fixed Buffer allocation length checks

On 32-bit platforms, where size_t is 32 bits, callers passing
int64_t lengths >= 2^32 to njs_buffer_alloc() had the value
silently truncated before reaching the UINT32_MAX check in
njs_array_buffer_alloc(), so Buffer.from({length: 0x100000000})
returned a zero-sized buffer instead of raising a RangeError.

Widened the size parameter to uint64_t so the value reaches
njs_typed_array_alloc() intact and the "invalid index" range
error fires consistently on 32-bit and 64-bit builds.

Buffer.concat() is protected by the same change: it likewise
reads an int64_t length from JS and forwards it to
njs_buffer_alloc() without an upper bound check of its own.
src/njs_buffer.c
test/buffer.t.js