]> git.kaiwu.me - njs.git/commit
Fixed heap-buffer-overflow in atom hash caused by Symbol().
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 17 Feb 2026 00:20:20 +0000 (16:20 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 24 Feb 2026 16:16:21 +0000 (08:16 -0800)
commit433478d5ecb4b1976e0291347a16eee8d75f70ad
tree4dca49736f8bebd6691f31bb293bf4a7c64d9cab
parent4ff0a7c7a67021958e513910a5e3b15bf2ff9fc8
Fixed heap-buffer-overflow in atom hash caused by Symbol().

Previously, there was a key_hash collision between strings and
symbols in the atom hash table that led to use of uninitialized memory
and desynchronization of vm->atom_id_generator.

In the atom hash, string entries used djb_hash(content) as key_hash
while symbol entries used raw atom_id. Since djb_hash produces arbitrary
uint32_t values and atom_ids grow monotonically from NJS_ATOM_SIZE,
these spaces overlapped. When a symbol's atom_id matched an existing
string's djb_hash, njs_flathsh_insert() invoked the test function which
read uninitialized fhq.key fields (the function expected string data,
but the caller never initialized it for symbols). Additionally,
atom_id_generator was incremented before the insert, so on failure the
counter diverged from the actual element count, causing subsequent
njs_atom_to_value() calls to read out of bounds.

The fix is to partition the key_hash space using bit 31.

Found by OSS-Fuzz.
src/njs_atom.c
src/test/njs_unit_test.c