Skip to content

Commit 4bed3bd

Browse files
limit size allocated by range operator to 1e7
1 parent 06a6b75 commit 4bed3bd

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/jsonata.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,19 @@ var jsonata = (function() {
849849
return result;
850850
}
851851

852-
result = new Array(rhs - lhs + 1);
852+
// limit the size of the array to ten million entries (1e7)
853+
// this is an implementation defined limit to protect against
854+
// memory and performance issues. This value may increase in the future.
855+
var size = rhs - lhs + 1;
856+
if(size > 1e7) {
857+
throw {
858+
code: "D2014",
859+
stack: (new Error()).stack,
860+
value: size
861+
};
862+
}
863+
864+
result = new Array(size);
853865
for (var item = lhs, index = 0; item <= rhs; item++, index++) {
854866
result[index] = item;
855867
}
@@ -1761,6 +1773,7 @@ var jsonata = (function() {
17611773
"T2011": "The insert/update clause of the transform expression must evaluate to an object: {{value}}",
17621774
"T2012": "The delete clause of the transform expression must evaluate to a string or array of strings: {{value}}",
17631775
"T2013": "The transform expression clones the input object using the $clone() function. This has been overridden in the current scope by a non-function.",
1776+
"D2014": "The size of the sequence allocated by the range operator (..) must not exceed 1e6. Attempted to allocate {{value}}.",
17641777
"D3001": "Attempting to invoke string function on Infinity or NaN",
17651778
"D3010": "Second argument of replace function cannot be an empty string",
17661779
"D3011": "Fourth argument of replace function must evaluate to a positive number",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "[1..10000000] ~> $count()",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": 1e7
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "[0..10000000] ~> $count()",
3+
"dataset": null,
4+
"bindings": {},
5+
"code": "D2014"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "[1..10000001] ~> $count()",
3+
"dataset": null,
4+
"bindings": {},
5+
"code": "D2014"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "[100..10000099] ~> $count()",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": 1e7
6+
}

0 commit comments

Comments
 (0)