Skip to content
Open
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
18 changes: 17 additions & 1 deletion packages/less/lib/less/functions/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,24 @@ export default {
to = start;
}

for (let i = from; i <= to.value; i += stepValue) {
// The loop below only ends if `i` moves up toward `to`. A step that is
// not a positive number (or too small to change `from`), or a string
// start or step (which `+=` would concatenate), would make it run
// until the process runs out of memory.
if (from <= to.value &&
!(typeof from === 'number' && typeof stepValue === 'number' && from + stepValue > from)) {
Comment on lines +69 to +70

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Compilation can still hang

The guard checks progress only at the start, so range(9007199254740991, 9007199254740992, 1) still hangs. The first addition advances to 9007199254740992, but adding 1 after that leaves the value unchanged because of JavaScript number rounding. The loop keeps appending that value until memory runs out. Check progress on each iteration and throw when the next value cannot advance.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other thread, fixed in 60b2724 with a per-step check and a fixture for this input.

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
throw { type: 'Argument', message: 'range() needs a numeric start and a positive numeric step' };
}

for (let i = from; i <= to.value;) {
list.push(new Dimension(i, to.unit));
// Near the float precision limit a step can stop moving `i`
// part way through, e.g. range(9007199254740991, 9007199254740992).
const next = i + stepValue;
if (!(next > i)) {
throw { type: 'Argument', message: 'range() needs a numeric start and a positive numeric step' };
}
i = next;
}

return new Expression(list);
Expand Down
3 changes: 3 additions & 0 deletions packages/test-data/tests-error/eval/range-step-negative.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test-rule {
width: range(1px, 5px, -1);
}
4 changes: 4 additions & 0 deletions packages/test-data/tests-error/eval/range-step-negative.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ArgumentError: Error evaluating function `range`: range() needs a numeric start and a positive numeric step in {path}range-step-negative.less on line 2, column 10:
1 .test-rule {
2 width: range(1px, 5px, -1);
3 }
3 changes: 3 additions & 0 deletions packages/test-data/tests-error/eval/range-step-precision.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test-rule {
width: range(9007199254740991, 9007199254740992, 1);
}
4 changes: 4 additions & 0 deletions packages/test-data/tests-error/eval/range-step-precision.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ArgumentError: Error evaluating function `range`: range() needs a numeric start and a positive numeric step in {path}range-step-precision.less on line 2, column 10:
1 .test-rule {
2 width: range(9007199254740991, 9007199254740992, 1);
3 }
3 changes: 3 additions & 0 deletions packages/test-data/tests-error/eval/range-step-zero.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test-rule {
width: range(1, 10, 0);
}
4 changes: 4 additions & 0 deletions packages/test-data/tests-error/eval/range-step-zero.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ArgumentError: Error evaluating function `range`: range() needs a numeric start and a positive numeric step in {path}range-step-zero.less on line 2, column 10:
1 .test-rule {
2 width: range(1, 10, 0);
3 }
Loading