Previously, TextEncoder.prototype.encodeInto() wrote directly into the
destination buffer without making a private copy of shared data. As a
result, encoding into r.requestBuffer in nginx modified the request
body seen by subsequent reads.
Now, the buffer is made writable before the write, as is done for
typed arrays.
The issue was introduced in
409004cb (0.4.4).
end = start + str.length;
array = njs_typed_array(dest);
- if (njs_slow_path(njs_is_detached_buffer(array->buffer))) {
- njs_type_error(vm, "detached buffer");
+ if (njs_slow_path(njs_typed_array_writable(vm, array) == NULL)) {
return NJS_ERROR;
}
"[b[0], new Uint8Array($r.arrayBuffer)[0]]"),
njs_str("64,208") },
+ { njs_str("var b = $r.buffer;"
+ "(new TextEncoder()).encodeInto('@', b);"
+ "[b[0], $r.buffer[0]]"),
+ njs_str("64,208") },
+
{ njs_str("$r.buffer instanceof Buffer"),
njs_str("true") },