]> git.kaiwu.me - njs.git/commit
Fix out-of-bounds read in Buffer.prototype.toString()
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 11 Jun 2026 04:11:06 +0000 (21:11 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 11 Jun 2026 15:21:53 +0000 (08:21 -0700)
commitdeba551476a5841ff4ca48df70784e3e0b7dece0
treefac71913136b32fbb3b6d20d6c0d880f81189573
parentc1635a7c11f1d6b5542f855f7f01148e656dba97
Fix out-of-bounds read in Buffer.prototype.toString()

Buffer.prototype.toString(encoding, start, end) on the njs engine
clamped start and end independently to the buffer length but never
enforced start <= end. With start > end the unsigned subtraction
end - start underflowed, the zero-length guard did not fire, and the
encoder read past the buffer.

Reject the start >= end case before computing the range, returning an
empty string to match Node.js semantics.

While here, add parallel missing functionality to QuickJS
for start and end arguments for Buffer.prototype.toString().
src/njs_buffer.c
src/qjs_buffer.c
test/buffer.t.js