Skip to content

range() never returns when the step is 0 or negative #4573

Open

Description

@goranai

To reproduce:

a {
  b: range(1, 10, 0);
}

The same happens with range(1px, 5px, -1), or with a step that comes from a variable and ends up as 0, like @step: 0; b: range(1, 10, @step);.

Run lessc test.less.

Current behavior:

lessc never finishes. Memory grows until Node stops with FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory (exit code 134).

The cause is the loop in packages/less/lib/less/functions/list.js:

for (let i = from; i <= to.value; i += stepValue) {
    list.push(new Dimension(i, to.unit));
}

When the step is 0 or negative, i never gets past to, so the list grows forever.

A string start or step does the same thing, because += joins strings. range("-5", 10) and range(-5, 10, "2") also never finish.

Expected behavior:

A normal Less error that points at the call, like other functions give for bad arguments. For example:

ArgumentError: Error evaluating function `range`: range() needs a numeric start and a positive numeric step in test.less on line 2

A wrong value in one variable should not hang a build or a watch process.

Environment information:

  • less version: master at 7133316
  • nodejs version: 24.19.0
  • operating system: Windows 11

I have a small fix with tests in a PR.

Validated with Claude Opus 5.5.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions