[Bug]: An array literal with a large array element throws "Maximum call stack size exceeded"

Open
#1,878 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
backend, data

Research direction

Start with Interpreter.ts and the ARRAY branch of Interpreter.evaluateAst at the listed lines 266, 269, 278, and 280. Check how large arrays are passed to push() and run the relevant evaluator tests with the supplied 40,000-row formula. Done means the array literal evaluates without a RangeError and the formula cell can be read.

Written by the indexing model from the issue text.

Description

Bug
Description

An array literal with a large array as an element throws a RangeError from buildFromArray and setCellContents:

const data = Array.from({length: 40000}, () => [1])
data[0].push('=SUM({VSTACK(A1:A40000,A1:A40000,A1:A40000,A1:A40000)})')

HyperFormula.buildFromArray(data, {licenseKey: 'gpl-v3'})
// RangeError: Maximum call stack size exceeded

Without the braces, =SUM(VSTACK(A1:A40000,A1:A40000,A1:A40000,A1:A40000)) returns 160000, as the equivalent formula does in Microsoft Excel Online. In Node.js 22 the error starts at about 125,000 rows or columns in one element. After it is thrown by setCellContents, the formula is stored, but reading the cell throws Value of the formula cell is not computed.

Cause: the ARRAY branch of Interpreter.evaluateAst spreads element arrays into push() (Interpreter.ts:266, :269, :278 and :280). Each spread passes one argument per row or value, and large arrays exceed the JavaScript engine's limit on the number of arguments in a call.

Expected: the array literal is built for any size that the other array functions accept.

Video or screenshots

N/A

Demo

Code snippet in the description.

HyperFormula version

3.5.0 (also develop at ec7512d21)

Your framework

None (Node.js)

Your environment

Node.js 22.23.4 on Linux

Dominant language
TypeScript
Stars
2.8k
Forks
175
Avg merge
2d 7h
Merged PRs (30d)
22

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from handsontable/hyperformula

All issues in handsontable/hyperformula

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.