Bound string construction with a maxStringLength option - #836
Closed
thiagojv wants to merge 1 commit into
Closed
Conversation
$pad takes its width straight from the expression with no ceiling, so a ~25 byte expression allocates until the engine's own string limit stops it — around 536 million characters on V8. options.sequence does not see this: it works by replacing push on sequences from createSequence, and pad builds a raw Array and joins it. The new option defaults to 1e7, the same ceiling the range operator already enforces, and can be raised or lowered per evaluation. Errors with D2016. Signed-off-by: Thiago Junqueira <thiagojv@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
|
A fix for this |
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.
Closes #835.
$padtakes itswidthstraight from the expression with no ceiling, so a ~25-byte expression allocates until the engine's own string limit stops it — around 536 million characters on V8.options.sequencedoes not see this: it works by replacingpushon sequences fromcreateSequence, andpadbuilds a rawArrayand joins it.Full measurements and the reasoning behind the default are in #835.
The change
options.maxStringLength, default1e7, adjustable per evaluation. Errors withD2016.The default is deliberately the same
1e7the range operator already enforces — it is this library's existing answer to "how much may a single operation allocate", andpadis the operation that does not observe it. Being a library constant it is also identical on every engine, which an engine-derived default would not be, andjsonata-es5.jsships the samepadto browsers.The check reads
this.optionsexactly asappend()already does foroptions.sequence, and it runs before the allocation rather than after.Compatibility
This is a behaviour change. It lowers the effective ceiling from the engine maximum to 10 M, so a
$padbetween those bounds succeeds today and would start failing. The escape hatch is one line:We do not believe anyone pads to ten million characters deliberately, but that is a guess about your users rather than a compatibility argument. If you would rather ship the option opt-in first and tighten the default in a later major, that is a one-line change here and we are glad to make it.
Scope
Only
pad— the one builtin taking an unbounded caller-supplied size. The same check is available to$replace,$joinor$stringif any is later found to amplify; we did not want to widen a first PR speculatively.Tests
Six new cases under
guardrails on string length, alongside the existingguardrails on sequence length: the default limit, a lowered limit, a raised limit, that the existing string counts toward the limit rather than only the padding added, and the two paths that must remain unaffected (padding within the limit, and a string needing no padding).Coverage is unchanged at 100% across all four metrics, including the new branches. Lint clean.
browserify,minifyandbuild-es5all run.Signed-off-by: Thiago Junqueira thiagojv@gmail.com
🤖 Generated with Claude Code