]> git.kaiwu.me - njs.git/commit
QuickJS: fix body_read_len mismatch in QuickJS readRequestJSON()
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 11 Jun 2026 04:20:04 +0000 (21:20 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 11 Jun 2026 15:21:53 +0000 (08:21 -0700)
commitf18625602a54e94ca7d41a1df33446493a6fe242
tree56b7698cc11ed2582be8d4183bc5e57129b6134c
parentccb1365bb181d8bbbe9dce0afff574fad1ed082d
QuickJS: fix body_read_len mismatch in QuickJS readRequestJSON()

Previously, for the JSON body type without a NUL terminator,
ngx_http_qjs_body_to_value() round-tripped the raw body through
qjs_string_create() (JS_NewStringLen) and JS_ToCString(), then parsed
the result with JS_ParseJSON() using the original body_read_len.
JS_NewStringLen() collapses invalid UTF-8 (a run of continuation bytes
becomes a single U+FFFD), so the byte length of the C string no longer
matches body_read_len. With a body containing such bytes the parser was
handed the wrong length and a valid body was truncated and rejected as a
SyntaxError.

The fix is to use JS_ToCStringLen() to capture the actual C string
length and pass it to JS_ParseJSON().
nginx/ngx_http_js_module.c