]> git.kaiwu.me - njs.git/commit
QuickJS: copy body bytes into ArrayBuffer
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 30 Oct 2026 01:44:24 +0000 (18:44 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 2 Nov 2026 14:42:35 +0000 (06:42 -0800)
commit8aeef5101a90c0b89851eaf5d646403d499993c5
tree4a3e2d8870f2541cface2beaaebe8e0d285c2ce5
parentf7d70ccdaafcdb35c3ff6cfa3e2587955b54d12e
QuickJS: copy body bytes into ArrayBuffer

Previously, r.readRequestArrayBuffer() and the arrayBuffer() methods
of fetch Request and Response objects returned an ArrayBuffer over
memory owned by a pool: the request pool or the engine pool.  The
buffer was created without a free function, which caused the
following problems:

  - with js_context_reuse, a buffer retained in the module scope
    outlived the pool and pointed to freed memory in the next
    request;
  - ArrayBuffer.prototype.transfer() called the NULL free function;
  - writes through the buffer modified the request body seen by
    subsequent r.requestText and r.readRequestText() calls, for a
    single buffer body directly in the nginx request buffers.

Now, the bytes are copied into memory owned by the ArrayBuffer.  For
Response.arrayBuffer() the body chain is joined directly into the
runtime memory, so the number of copies is unchanged.

The issue was introduced in b7f76b71 (0.9.1) and 7684d702 (0.9.9).

Based on a patch by Vadim Zhestikov.
nginx/ngx_http_js_module.c
nginx/ngx_qjs_fetch.c