Skip to content

JSE-58: maxCellTextLength limit, message excerpts of long text, maxIssues for importDataset - #132

Merged
securedeveloper merged 2 commits into
mainfrom
fix/jse-58-cell-text-limit
Dec 1, 2026
Merged

securedeveloper merged 2 commits into
mainfrom
fix/jse-58-cell-text-limit

Conversation

@securedeveloper

@securedeveloper securedeveloper commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Gap

  1. Issue and warning messages copied the whole cell text. importDataset's TYPE issue was built as ${ref}: ${JSON.stringify(String(value))} is not a ${type}., so one long shared string used by many cells made one full copy per message.
  2. Nothing limited one cell's text. maxXmlTokenLength limits tags, not the text between them, though its documentation read as if it capped cell values: a 16,000,000-character shared string read with maxXmlTokenLength at 64 KiB.

Measurements (Node 26, Apple-silicon laptop, --max-old-space-size=4096)

File 2.2.0 This branch
123 KB xlsx, one 16,000,000-character shared string as the date cell of 20 rows, types: { date: 'date' } 20 issues, 320,000,432 characters of messages (longest 16,000,022), 359 MB heap refused in 15 ms: LimitError, details: { limit: 'maxCellTextLength', value: 1048577, max: 1048576, part: 'xl/sharedStrings.xml' }
Same, 10,000 rows (174 KB) out of memory after 0.96 s (4.4 GB RSS) refused in 17 ms (0.12 s process, 138 MB RSS). With maxCellTextLength: 16_000_000: 10,000 issues in 0.2 s, 1,108,898 characters of messages, longest 112, 85 MB heap
48 KB xlsx, a 60,000-character string in all 20 columns of 1,000 rows, every column forced to number 20,000 issues, 1,200,497,920 characters, 1,219 MB heap 20,000 issues in 75 ms, 2,177,920 characters, longest 110, 25 MB heap

Message after: A2: "iiiosmmqqoaskgeeqqsaayieoswwuicoiscoqagigqoksuwueamisgicmkwcsimc"… (16000000 characters) is not a date.

What changes

ReadLimits.maxCellTextLength (optional member, default 1,048,576 characters, in DEFAULT_READ_LIMITS). One cell's text as the cell will hold it: a shared string (<si>) or inline string (<is>), rich-text runs together and phonetic runs left out, and the text of a <v> and of an <f>. Counted in UTF-16 code units after entities and _xHHHH_ escapes are decoded, while the text streams in (a streaming counter holds back at most 6 characters that may start an escape), so a longer text is refused before it is held whole. Fails as the other limits do: LimitError, LIMIT_EXCEEDED, details: { limit: 'maxCellTextLength', value: max + 1, max, part, ref? } (ref for sheet cells).

Default on, at 1 Mi:

  • Excel's own cell limit is 32,767 characters (Google Sheets 50,000), so nothing Excel writes comes near it; 32 times that leaves room for files from writers that allow longer text (openpyxl, LibreOffice, scripts).
  • It matches CSV's existing default maxFieldBytes (1 MiB), so with both defaults the CSV parser behaves exactly as before (a field over 1 Mi characters has at least that many bytes, and maxFieldBytes is still checked first).
  • It refuses the measured 16,000,000-character file. Off by default would leave every consumer exposed until they opt in.

Where the option goes:

  • read, the worker client's read: limits.maxCellTextLength.
  • parseCsv / readCsv, the worker client's parseCsv: new CSV option maxCellTextLength, alongside maxFieldBytes (both apply).
  • importDataset (and its worker call): limits.maxCellTextLength for xlsx and CSV. For CSV it is passed through; CSV's maxFieldBytes stays at 1 MiB unless maxCellTextLength is above 1,048,576 (more characters than 1 MiB can hold), and then becomes 3 × maxCellTextLength. A byte cap is never loosened otherwise (spreading DEFAULT_READ_LIMITS keeps 1 MiB).
  • readSheetNames applies it to defined-name formulas.

Excerpts in messages. Text over 128 characters is quoted as its first 64 characters, … and its length; text up to 128 characters is quoted as before, so ordinary messages are unchanged. Codes and fields (ref, sheet, part, column, details) are never shortened. Changed builders:

  • importDataset issues: TYPE (also from the public coerceColumns), DATE_ORDER_AMBIGUOUS (column key), ERROR_CELL (error text).
  • Reader warnings: INVALID_CELL_REF, CELL_OUT_OF_BOUNDS, INVALID_SHARED_STRING (the <v> text), ROWS_TRUNCATED (sheet name), MISSING_PART (target, sheet name), BROKEN_OPTIONAL_PART (part), HYPERLINK_RANGE_REDUCED (range).
  • Errors: XML element names in XML_MALFORMED messages, the part-name prefix withPart adds, zip entry names (ZIP_ENCRYPTED, ZIP_UNSUPPORTED_METHOD, ZIP_INVALID, ZIP_CRC_MISMATCH, maxEntryBytes), and OPC case-clash part names.
  • Not changed: CSV warnings (they quote no field text) and builder/writer messages (developer input, not file text). Messages are not a documented contract; no snapshot test quotes a long value.

importDataset maxIssues (default 100,000, an integer of at least 1). No limit existed. The list is now bounded while it is built, not filtered afterwards: until maxIssues issues are kept every issue is kept, in the 2.2 order; past it an issue is kept only if it is the first of its code, and the others are counted in meta.droppedIssues: { total, byCode } (present only when something was dropped). Each code has one severity, so a list cut short still holds an error whenever one was dropped. The same idea as the warning cap from JSE-46, reported in meta rather than as a new issue code so that ImportIssueCode does not widen. To bound the list while it is built, the pipeline now decides the mapping before converting values and drops issues on unmapped columns as they occur; the TYPE-then-REQUIRED suppression uses a per-column bitmap of failed rows instead of a set of every TYPE issue.

Docs. maxXmlTokenLength (JSDoc and docs/api.md §5.2) now says it does not limit text and points to maxCellTextLength; new limit row in §5.2, CSV option in §5.3, maxIssues and droppedIssues and the excerpt rule in §5.6, the excerpt rule in §7.3, a "Huge cell text" row in §8, README limits line.

Compatibility. Additive: new optional members and options; for files within the new limit, results, warnings and errors are unchanged except the intended message shortening (fuzz below). A complete 2.2-style ReadLimits literal still compiles (consumer-ts fixture added). Changeset: minor (new options plus a safety fix, as for maxSheets/maxItems in #130).

Tests

Written first and run red against the unchanged source (CSV option ignored, the 16 M file not refused, the 10,000-row import test crashed the vitest worker with SIGABRT), then green.

  • test/read/cell-text-limit.test.ts: the default; a 32,767-character cell reads with defaults; the 16,000,000-character file (built in the test, under 400 KB) is refused with part, reads with only maxXmlTokenLength lowered to 64 Ki when maxCellTextLength is raised, and is refused on the deferred (maxRows) path; at/over the limit (10 reads at 10, refused at 9) for shared string, two <t>, shared rich text, inline string, inline rich text, t="str" <v>, number <v>, formula, entities, _xHHHH_ escapes; details.ref; phonetic runs and never-decoded strings do not count; validation through read and readSheetNames; StringItem throws at the chunk that passes the limit; the streaming counter equals decodeXstring(s).length for every split of 2,000 seeded random strings (over 10,000 splits); excerpt rules; long file text in INVALID_CELL_REF, INVALID_SHARED_STRING, ROWS_TRUNCATED, HYPERLINK_RANGE_REDUCED, MISSING_PART and an XML error stays under 400 characters with full fields.
  • test/csv/cell-text-limit.test.ts: defaults unchanged; at/over the limit with details.value, ref; unquoted length; both limits apply; readCsv; validation.
  • test/import/issue-bounds.test.ts: the 16 M file refused by default; with the limit raised, 10,000 rows give 10,000 issues of at most 120 characters; 60,000 characters in 20 columns × 1,000 rows give 20,000 issues of at most 120 characters; the same in CSV; short messages unchanged; coerceColumns; DATE_ORDER_AMBIGUOUS; maxIssues default, cap, first-of-each-code, dropped columns never count, REQUIRED still suppressed after a dropped TYPE issue, validation; limits.maxCellTextLength reaches CSV and raising it lets a 1.5 M field through.
  • test/worker/worker.test.ts: maxCellTextLength through read, parseCsv and importDataset, and maxIssues/droppedIssues across the boundary.

Local: npm run typecheck, npm test (1,182 passed; the one failure, test/format/libreoffice.test.ts, fails identically on main with the local LibreOffice and is not part of the required job), npm run build, npm run lint, npm run smoke, npm run consumer-ts (TypeScript 5.0 to 7.0), dependency guard, npm run docs:check.

Differential fuzz against 2.2.0

A seeded generator of workbooks (shared strings with runs, phonetic runs, _xHHHH_ and entity text; inline strings; str, n, b, e, d cells with valid and invalid values; invalid, out-of-bounds and long references; long sheet names; hyperlink ranges; a missing shared-strings target; occasional malformed XML) and CSV text (quotes, doubled quotes, mixed delimiters, long fields), run through read (random richText, maxRows, rawText), importDataset on the xlsx (random types, header, schema with required and typed fields), parseCsv (random inferTypes, strict mode, maxRows) and importDataset on the CSV (random types, locale.dateOrder), against the published 2.2.0 tarball. Results and errors must be deep-equal; a message may differ only by being shorter and carrying the excerpt marker.

seed iterations cases (read / importXlsx / parseCsv / importCsv) identical only a message shortened errors in both, identical diverged
58 5,000 30,000 (5,000 / 5,000 / 10,000 / 10,000) 27,140 2,860 1,028 0
2026 5,000 30,000 (5,000 / 5,000 / 10,000 / 10,000) 27,152 2,848 1,032 0

The first trial run found that a 65 to 80 character value got a longer "excerpt" than itself; quoting text in full up to 128 characters fixed that before these runs.

Performance

bench/run.mjs A/B against 2.2.0 at 1M cells (two interleaved rounds): read plain 560/575 ms vs 699/548 ms, unique 1,089/1,164 ms vs 1,148/1,152 ms; csv-read plain 58/60 vs 65/63 ms, unique 81/74 vs 99/80 ms. Within noise; heap unchanged.

Review fixes (second commit)

  • Non-cell text: maxCellTextLength also bounds header/footer text, defined-name formulas and core, extended and custom document property values, counted as written while they stream in (details.part names the part). Before, a 1.67 MB file gave a 100,000,000-character <oddHeader>.
  • Which limit covers which text:
Text Bounded by
Shared strings, inline strings, <v>, formulas maxCellTextLength
Header/footer text, defined-name formulas, document property values maxCellTextLength
Attribute text: sheet names, defined-name names, custom property names, hyperlink targets (relationship Target), locations, tooltips, display text, number format codes, sqref maxXmlTokenLength (whole tag)
Comments/notes, threaded comments, tables and their column names, drawings, pivots Not read (UNSUPPORTED_PART)
Data validations and their prompts Not read (skipped)
  • The overlap zip error quotes excerpts of entry names.
  • importDataset and the CSV byte cap: see "Where the option goes" above.
  • Abort order: an abort raised in onProgress at "dataset" wins over a bad types/mapping option again, as in 2.2.0.
  • maxIssues: Infinity means no cap.
  • 500,000 TYPE issues: 2.2.0 threw RangeError: Maximum call stack size exceeded; this branch keeps 100,000 and counts 400,000 (pinned by a test).
  • Mutation-pinning tests:
    • With both defaults, a 1 Mi + 1 character CSV field reports maxFieldBytes; this fails if the checks are swapped.
    • A number <v> of _x0041__x0042_ counts 14 characters; this fails if it is decoded.
  • Docs:
    • Say what is bounded and what is not. Not bounded: references multiplying work and memory (one long shared string used by many cells, shared formulas, long header titles as row keys, worker copies).
    • Explain details.value per limit in one place.
    • Give server guidance in the security section.
  • Changeset: reworded to match.
  • Fuzz after the fixes: seeds 58 and 2026, 30,000 cases each, 0 divergences.

…maxIssues for importDataset

- New optional ReadLimits.maxCellTextLength (default 1,048,576): one cell's
  text (shared string, inline string, <v>, formula), counted after decoding
  while it streams in. Also a CSV option, and importDataset passes
  limits.maxCellTextLength to the CSV parser.
- Warning, issue and error messages quote text over 128 characters as a
  64-character excerpt plus its length; fields are unchanged.
- importDataset: maxIssues (default 100,000) bounds the issue list while it is
  built; dropped issues are counted in meta.droppedIssues, and the first issue
  of each code is always kept.
- maxXmlTokenLength documentation says it does not limit text.
…r, docs

- maxCellTextLength also bounds header/footer text, defined-name formulas
  and document property values, counted as written while they stream in.
- The overlap error quotes an excerpt of long entry names.
- importDataset keeps CSV's 1 MiB maxFieldBytes unless maxCellTextLength
  asks for more characters than 1 MiB can hold.
- An abort raised before the types and mapping are decided wins over a bad
  option again, as in 2.2.0.
- maxIssues accepts Infinity (no cap).
- Tests pin the CSV check order, raw counting of number <v> text and the
  500,000-issue case that overflowed the call stack in 2.2.0.
- Docs and changeset state what is bounded and what is not, which limit
  covers which text, details.value per limit, and server guidance.
@securedeveloper
securedeveloper merged commit 143a1b3 into main Dec 1, 2026
9 checks passed
@securedeveloper
securedeveloper deleted the fix/jse-58-cell-text-limit branch December 1, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant