The spreadsheet in the following file causes gridjs-spreadsheet to enter an infinite loop trying to calculate the width of all the columns:
long-cell.xlsx.zip (7.2 KB)
The minimal repro is:
- Hide column A (so that its width is set to 0)
- Insert text in cell B1 such that it overflows past column C
- Insert some short text in cell C2
The problem is with the following check in loadData
:
if (s.cols.maxwidth) {
var S = s.cols.sumWidth(0, s.cols.len);
s.cols.maxwidth > S && (s.cols.len += (s.cols.maxwidth - S) / s.cols.getWidth(0) + 1);
}
s.cols.getWidth(0)
returns 0, because the first column is hidden, so the division results in Infinity
. s.cols.len
then gets set to Infinity
, so when totalWidth
is called (eg: when setting the active sheet), sumWidth
is invoked with Infinity
as the second arg, resulting in an infinite loop.