Previously, allocation of large array literals may result in
null-pointer dereference. The reason is that njs_array_alloc() may
return a slow array when size is large enough, but the instruction
code assumes that array is always flat.
The fix is to check fast_array flag before accessing array->start.
This closes #473 issue on Github.
if (code->ctor) {
/* Array of the form [,,,], [1,,]. */
- value = array->start;
- length = array->length;
-
- do {
- njs_set_invalid(value);
- value++;
- length--;
- } while (length != 0);
+ if (array->object.fast_array) {
+ value = array->start;
+ length = array->length;
+
+ do {
+ njs_set_invalid(value);
+ value++;
+ length--;
+ } while (length != 0);
+ }
} else {
/* Array of the form [], [,,1], [1,2,3]. */
{ njs_str("(new Function('return 5' + '** 1'.repeat(2**13)))()"),
njs_str("5") },
+ { njs_str("var a = (new Function('return [' + ','.repeat(2**16) + ']'))();"
+ "njs.dump(a)"),
+ njs_str("[<65536 empty items>]") },
+
{ njs_str("(new Function('var a = 7; return a' + '= a'.repeat(2**13)))()"),
njs_str("7") },