Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/jsonata.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,19 @@ var jsonata = (function() {
return result;
}

result = new Array(rhs - lhs + 1);
// limit the size of the array to ten million entries (1e7)
// this is an implementation defined limit to protect against
// memory and performance issues. This value may increase in the future.
var size = rhs - lhs + 1;
if(size > 1e7) {
throw {
code: "D2014",
stack: (new Error()).stack,
value: size
};
}

result = new Array(size);
for (var item = lhs, index = 0; item <= rhs; item++, index++) {
result[index] = item;
}
Expand Down Expand Up @@ -1761,6 +1773,7 @@ var jsonata = (function() {
"T2011": "The insert/update clause of the transform expression must evaluate to an object: {{value}}",
"T2012": "The delete clause of the transform expression must evaluate to a string or array of strings: {{value}}",
"T2013": "The transform expression clones the input object using the $clone() function. This has been overridden in the current scope by a non-function.",
"D2014": "The size of the sequence allocated by the range operator (..) must not exceed 1e6. Attempted to allocate {{value}}.",
"D3001": "Attempting to invoke string function on Infinity or NaN",
"D3010": "Second argument of replace function cannot be an empty string",
"D3011": "Fourth argument of replace function must evaluate to a positive number",
Expand Down
8 changes: 8 additions & 0 deletions test/test-suite/groups/range-operator/case021.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"expr": "[1..10000000] ~> $count()",
"dataset": null,
"bindings": {},
"result": 1e7,
"timelimit": 10000,
"depth": 10
}
6 changes: 6 additions & 0 deletions test/test-suite/groups/range-operator/case022.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"expr": "[0..10000000] ~> $count()",
"dataset": null,
"bindings": {},
"code": "D2014"
}
6 changes: 6 additions & 0 deletions test/test-suite/groups/range-operator/case023.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"expr": "[1..10000001] ~> $count()",
"dataset": null,
"bindings": {},
"code": "D2014"
}
8 changes: 8 additions & 0 deletions test/test-suite/groups/range-operator/case024.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"expr": "[100..10000099] ~> $count()",
"dataset": null,
"bindings": {},
"result": 1e7,
"timelimit": 10000,
"depth": 10
}