]> git.kaiwu.me - njs.git/commit
QuickJS: fixed Buffer.from() and encoding error paths
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 21 May 2026 23:01:56 +0000 (16:01 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 26 May 2026 21:45:24 +0000 (14:45 -0700)
commita1d2131f664f725bb9c187225ab7582f2a5efa6c
treea14c591431928029544865593c41d9e6b5dab180
parentbf2a76941e35e21959de0c880b9ed9f217462190
QuickJS: fixed Buffer.from() and encoding error paths

Freed the typed array constructor object after reading constructor.name
while detecting Float32Array in Buffer.from().  This keeps the exception
path from leaking the constructor object.

Handled JS_ToCString() failure for constructor.name before comparing the
name, avoiding a NULL dereference when the property converts to an
exception, such as a Symbol value.

Divided the source offset by the element size in qjs_buffer_from()
typed-array path so the offset addresses the right element for 2-, 4-,
and 8-byte element types (previously the offset was left in byte units
while size was already in element units).

Added a NULL check on JS_ToCStringLen() in qjs_buffer_encoding(), and
moved the JS_FreeCString() call after the JS_ThrowTypeError() so the
encoding name remains valid while the error message is formatted.

Routed array source errors in qjs_buffer_from_object() through a single
fail label so the destination buffer is freed once on every failure path
(previously leaked on three of them).
src/qjs_buffer.c
test/buffer.t.js