[njs] Fixed Array.prototype.concat() with exotic argument object.

Dmitry Volyntsev xeioex at nginx.com
Tue Jan 18 15:35:22 UTC 2022


details:   https://hg.nginx.org/njs/rev/3e86977c253d
branches:  
changeset: 1808:3e86977c253d
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Jan 18 15:35:00 2022 +0000
description:
Fixed Array.prototype.concat() with exotic argument object.

The issue was introduced in 2c1382bab643.

diffstat:

 src/njs_array.c          |  2 +-
 src/test/njs_unit_test.c |  7 +++++++
 2 files changed, 8 insertions(+), 1 deletions(-)

diffs (29 lines):

diff -r 7467158d9f37 -r 3e86977c253d src/njs_array.c
--- a/src/njs_array.c	Fri Jan 14 14:40:27 2022 +0000
+++ b/src/njs_array.c	Tue Jan 18 15:35:00 2022 +0000
@@ -1743,7 +1743,7 @@ njs_array_prototype_concat(njs_vm_t *vm,
                 return NJS_ERROR;
             }
 
-            if (njs_is_fast_array(e)) {
+            if (njs_is_fast_array(e) || njs_fast_object(len)) {
                 for (k = 0; k < len; k++, length++) {
                     ret = njs_value_property_i64(vm, e, k, &retval);
                     if (njs_slow_path(ret != NJS_OK)) {
diff -r 7467158d9f37 -r 3e86977c253d src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Fri Jan 14 14:40:27 2022 +0000
+++ b/src/test/njs_unit_test.c	Tue Jan 18 15:35:00 2022 +0000
@@ -12857,6 +12857,13 @@ static njs_unit_test_t  njs_test[] =
               "a.concat(b)"),
       njs_str("1,2,3,4,5") },
 
+    { njs_str("Boolean.prototype.length = 2;"
+              "Boolean.prototype[0] = 'a';"
+              "Boolean.prototype[1] = 'b';"
+              "Boolean.prototype[Symbol.isConcatSpreadable] = true;"
+              "[].concat(new Boolean(true))"),
+      njs_str("a,b") },
+
     { njs_str("var o = {}, n = 5381 /* NJS_DJB_HASH_INIT */;"
               "while(n--) o[Symbol()] = 'test'; o[''];"),
       njs_str("undefined") },



More information about the nginx-devel mailing list