]> git.kaiwu.me - njs.git/commit
Buffer: fix infinite loop when filling from a zero-length typed array
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 12 Jun 2026 01:34:26 +0000 (18:34 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 16 Jun 2026 23:22:57 +0000 (16:22 -0700)
commit8b0a1a87b1b3bdb20cac302a8dda6202b47dd39b
treefa047db6a954850739f09ba8744625e17fd7bb54
parent943a9f358feda2e9b28445a781464a291d0b763e
Buffer: fix infinite loop when filling from a zero-length typed array

njs_buffer_fill_typed_array() advanced the destination by
njs_min(byte_length, end - to) each iteration.  When the fill source
typed array was empty, the step was always zero and the loop spun
forever, hanging the worker on attacker-controlled input.

Zero-fill the range for an empty source, matching njs_buffer_fill_string()
and the QuickJS qjs_buffer_fill().
src/njs_buffer.c
test/buffer.t.js