]> git.kaiwu.me - njs.git/commit
Buffer: reject oversized QJS alloc() and concat() sizes
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 24 Sep 2026 22:53:30 +0000 (15:53 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 25 Sep 2026 23:00:29 +0000 (16:00 -0700)
commit5832bed4ecc1cb4cb199594ef8091f9a5b7b6195
tree3e1c9d36a61577f1f87f2caad5143f7ffc6f5ca6
parentd2b6e6db651add450bfa2a8752a5feff5a0ec573
Buffer: reject oversized QJS alloc() and concat() sizes

Buffer.alloc() and Buffer.concat() converted sizes with JS_ToUint32(),
which wraps values modulo 2^32: Buffer.alloc(2 ** 32 + 16) returned a
16-byte buffer.  Use JS_ToIndex() instead, so these sizes throw a
RangeError.

In Buffer.concat(), the total length of the list could also overflow the
32-bit accumulator.  Keep it in 64 bits and check it against
QJS_BUFFER_MAX_LENGTH.  The overflow now throws a RangeError instead of a
TypeError, as in Node.js.
src/qjs_buffer.c
test/buffer.t.js