]> git.kaiwu.me - njs.git/commit
Fix Array.prototype.sort() with huge sparse arrays
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 4 Sep 2026 01:48:39 +0000 (18:48 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 4 Sep 2026 21:53:08 +0000 (14:53 -0700)
commit71e09e9cdbf0a6626da3cec8f02cd637bbf8ae0e
tree56f348818656aab3d400fdbe3e94fdc9fb3e8063
parent9c20d77307a4bec4bd59b3535de28a328a18a402
Fix Array.prototype.sort() with huge sparse arrays

Previously, sort deleted every index from the compacted output position to
the original length.  A sparse array with length near 2^32 therefore caused
billions of property-delete operations and unbounded memory growth.

The fix is to retain the direct cleanup loop for fast arrays and, for slow
arrays, enumerate and delete only existing indexed properties in the range.

The issue was introduced in 1a2a65f7 (0.8.0).

This closes #1095 issue on GitHub.
src/njs_array.c
src/test/njs_unit_test.c