Repository navigation
JSE-68: maxColumns read limit, dataset empty fields counted against maxCells - #136
Merged
Merged
Conversation
…axCells
- New optional ReadLimits.maxColumns (default 16,384, Excel's width): the
highest column a kept cell uses on each sheet read, checked as each cell is
kept (a styled empty cell and a hyperlink's cell count; <dimension> is not
trusted). LimitError LIMIT_EXCEEDED, details { limit: 'maxColumns', value
(the column number), max, part, ref }. Passed through read, importDataset
and the worker client; readSheetNames accepts and validates it.
- CSV: new option maxColumns, fields in one record (default 1,048,576), with
the same error; importDataset passes limits.maxColumns to CSV when given.
- importDataset counts the empty fields its dataset pads short rows with
(null for a column a data row has no cell in) against limits.maxCells, for
xlsx and CSV, before any row is built; details { limit: 'maxCells', value,
max, rows, columns }. A title in every column to XFD over 10,000 three-cell
rows is refused in about 0.6 s instead of exhausting a 4 GB heap.
- Docs: limits table, details.value, CSV options, import behaviour, security
table and server guidance; README limits line.
…invalid shared-string cells count toward maxColumns on both paths
Keeps JSE-62's shared-formula rows in docs §8 and the README beside the JSE-68 width rows, and documents the review's notes on the dataset count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gap
A 614 KB .xlsx whose row 1 has a title in every column up to XFD (16,384 columns), followed by 10,000 rows of 3 cells, made
importDatasetrun out of a 4 GB heap after about 8 s (measured by a consumer's security review on 2.3.0). Every data row became an object with 16,384 keys (about 164 million fields).maxCellscounts stored cells only (about 46,000 here), so it never tripped; 1-character titles behave the same (width, not text). The library gave callers no width limit.Why every row has 16,384 keys:
toDataset's contract is that each data row carries a key for every column,nullwhere the row has no cell. The contract is kept; its cost is now bounded.Measurements (Node 26, Apple-silicon laptop,
--max-old-space-size=4096, files built with the library's writer)importDatasetdefaultsLimitError,details: { limit: 'maxCells', value: 10008791, max: 10000000, rows: 611, columns: 16384 }limits: { maxColumns: 256 }details: { limit: 'maxColumns', value: 257, max: 256, part: 'xl/worksheets/sheet1.xml', ref: 'IW1' }importDatasetdefaultslimits: { maxColumns: 256 }readdefaultsAPI and defaults
ReadLimits.maxColumns(optional member, inDEFAULT_READ_LIMITS, default 16,384). The highest column used by any cell the read keeps, on each sheet read: a cell with a value, a styled empty cell (withstyleson), a hyperlink's cell. Checked as each cell is kept while the sheet streams in, so a wider sheet stops at its first cell past the limit and later rows are not read;<dimension>is not trusted, and an empty unstyled<c>(which the reader does not keep) does not count.LimitErrorLIMIT_EXCEEDED,details: { limit: 'maxColumns', value, max, part, ref },value= the offending cell's 1-based column number. Passed throughread,importDataset(limits.maxColumns) and the worker client;readSheetNamesaccepts and validates it (it reads no cells).CELL_OUT_OF_BOUNDSand still are. Docs and the server guidance say to set it low (for example 256) for untrusted files.CSV
maxColumns(newCsvParseOptionsmember, besidemaxFieldBytes/maxCellTextLength; no fields-per-record limit existed). Fields in one record, refused while the record is read with the same error (details: { limit: 'maxColumns', value: max + 1, max, ref }); a trailing delimiter is a field; the record read only to findmaxRowsreached is not checked. Default 1,048,576: 64 times Excel's width and wider than any spreadsheet, so no CSV that 2.3 parsed is refused; a record that wide is at least 1 MiB of text, soparseCsvoutput stays linear in its input.importDatasetpasseslimits.maxColumnsto CSV only when given (otherwise the CSV default applies, not the xlsx one). Note:importDatasetalready rejected CSV wider than 16,384 columns in 2.3 (ValidationErrorfrom the dataset step); unchanged.Dataset size in
importDataset. The empty fields the dataset pads rows with (a column a data row has no cell in) are counted againstlimits.maxCells(default 10,000,000), for xlsx and CSV, row by row before any row is built; past it:LimitError,details: { limit: 'maxCells', value, max, rows, columns }. Cells the rows do have are not counted (for xlsx the reader already counted them), so dense data is never refused by it, and a dataset holds at most the sheet's cells plusmaxCellsfields. A pre-check skips the count when rows × columns cannot pass the limit, so ordinary imports do no extra work. ReusingmaxCellsinstead of a new option: it is the budget callers already set for "values the read builds", and the padding is exactly that.toDataset(public) is unchanged and has no budget. For CSV this is the first use ofmaxCells; a CSV import that pads more than 10 M empty fields (ragged or wide-and-short) is now refused under the defaults.Additive: new optional members and options; results for inputs within the limits are identical to 2.3.0 (fuzz below). An invalid
limits.maxCellsfor a CSV import is now aTypeError(it was ignored); for xlsx the error and its order are as before.Tests (written first; red on 2.3: the worker OOM-aborted on the measured files)
test/read/max-columns.test.ts: default 16,384; XFD reads and refs beyond XFD still warn; the measured file built in the test (<700 KB): refused withmaxColumns: 256atIW1(row 1, so no data row read), and under defaults refused by the dataset count at exactly row 611 withvalue≤ max + one row (work asserted, not wall clock alone); 1-character titles; exactly-at-limit reads, one more refused; one sparse cell in XFD counted; cells withoutr; empty unstyled vs styled cells; hyperlink cells; per-sheet and only sheets read; rows pastmaxRows; lying<dimension>; validation andreadSheetNames.test/import/dataset-size.test.ts: the count stops after reading only 11 rows of 100,000 (proxy-counted row reads) and builds none; at-the-budget output equals the unbounded output; dense rows, empty rows, null cells,range; CSV wide header refused under defaults;limits.maxCellsbudget;preview.test/csv/max-columns.test.ts: default, at/over the limit, trailing delimiter, quoted fields,readCsv,maxRows, validation,importDatasetpass-through.test/worker/worker.test.ts:maxColumns(read, parseCsv, importDataset xlsx and CSV) and the datasetmaxCellscross the boundary.scripts/consumer.mjs: a complete 2.3-styleReadLimitsliteral (withoutmaxColumns) still compiles;DEFAULT_READ_LIMITS.maxColumns; CSVmaxColumns.npm run consumer-ts: TypeScript 5.0–7.0 pass.test/read/sheet-list-linear.test.tsgainedlimits.maxColumns.Differential fuzz against the released 2.3.0
Harness written for this ticket (kept outside the repo): the released tarball from
npm pack [email protected]against this branch's build. Random cases: hand-built xlsx packages (stored zip; cells with and withoutr, refs beyond XFD, every cell type, styled and unstyled empty cells, shared formulas with SUBTOTAL, hyperlinks far to the right, lying<dimension>, merges, hidden first sheet, 1–3 sheets), workbooks written by 2.3.0 (header widths 3–16,384, sparse rows, dates, nulls), and CSV (4 delimiters, 3 newline styles, quotes, stray quotes, blank lines, ragged and up to 3,000-field records, BOM, trailing delimiter). Options randomised:limits.maxColumns,limits.maxCells,styles,maxRows,sheets,range,preview,sheet,header, CSVdelimiter/inferTypes/skipEmptyLines/mode/maxRows/maxColumns. Each case runsread,readSheetNames,importDataset(xlsx or CSV) andparseCsv; results and errors (name, code, message, details) must be deep-equal, except a refusal by the new limits (maxColumns, or the dataset'smaxCellscount, recognised bydetails.rows) where 2.3.0 did not refuse.The 104,000-case run used a build from before the last change (the
limits.maxCellscheck inimportDatasetmoved afterread, which affects only invalid option values, not generated here); the second run is on the head.Docs
docs/api.md§5.2 (ReadLimits block, newmaxColumnsrow,maxCellsrow,details.valuenote), §5.3 (CSV option), §5.6 (limitscomment, "Dataset size" behaviour), §8 ("Wide sheets" row, server guidancemaxColumns: 256); README limits line; changeset (minor).Review fixes
maxItems, notmaxCells) built full-width rows for free. A cell with neither value nor formula (hyperlink-only or style-only) now counts as an empty field. Tests: 16,384 titles over 100 rows of hyperlinks withmaxCells: 100000(with and without a schema) refused at row 7 (value114,681); a consumer's settings (maxColumns256,maxCells1,000,000), 256 titles over 20,000 rows of 1 cell and 255 hyperlinks, refused at row 3,922 (value1,000,110); hyperlink cells that hold values are unchanged.maxColumnson both paths (withReadOptions.maxRowsit was counted when stored; without, it was dropped first). Test pins both.typeskey naming no column, ormaxRows); the ragged-CSV example (more than 500,000 rows of 10 fields under 30 columns are refused under the defaults); CSV imports validatelimits.maxCells; spreadingDEFAULT_READ_LIMITSinto a CSV import givesmaxColumns: 16384, aLimitErrorinstead of 2.3'sValidationError; the publictoDatasetis not bounded by the count (setmaxColumnson theread); the measured worst case under defaults (about 610 rows × 16,384 columns: 3.1 s, 1.13 GB).origin/main(JSE-69: 'day' takes the day as written for ISO text with an offset #137 JSE-69, JSE-62: bounded shared formulas (scan once, Excel's limit for masters, copies under maxCellTextLength), importDataset without shifting #138 JSE-62); the read call inpipeline.tskeeps JSE-62's internalsharedFormulaTextoption, and limits (incl.maxColumns) pass through as before; docs §8 and the README keep both sets of rows.