]> git.kaiwu.me - njs.git/commit
WebCrypto: fix AES-CTR out-of-bounds write on empty input
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 29 Oct 2026 16:17:33 +0000 (09:17 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 29 Oct 2026 20:00:23 +0000 (13:00 -0700)
commitefce2469de8b784ed6497b20cfac10236e107884
treec0caeb4b70052defb82fd13b8ae4e3c76fcfffbe
parent4ee6f12facd274f2c1202c1bf9edbb24aa64c2d0
WebCrypto: fix AES-CTR out-of-bounds write on empty input

Previously, the AES-CTR block count helper computed the number of
blocks as "1 + (dend - 1) / dsor".  This underflows for a zero-length
input, so njs_ceil_div(0, 16) and qjs_ceiling_div(0, 16) returned
2^28 instead of 0.

The fix is to use the zero-safe "(dend + dsor - 1) / dsor" form.

The njs engine code was introduced in 7b2b7612 (0.7.0) and the
QuickJS counterpart in 75ca26f8 (0.8.10).
external/njs_webcrypto_module.c
external/qjs_webcrypto_module.c
test/webcrypto/aes.t.mjs