Validate CLI numeric limits#1083
Open
He-Pin wants to merge 1 commit into
Open
Conversation
Motivation: sjsonnet accepted invalid numeric CLI limits for stack frames, trace cropping, and parser recursion depth. Non-positive stack limits created a broken runtime setting, negative trace limits behaved like an undocumented full-trace setting, and negative parser recursion depth reached the parser as Parsing exceeded maximum recursion depth of -1. Modification: Validate --max-stack >= 1, --max-trace >= 0, and --max-parser-recursion-depth >= 0 after CLI parsing and before constructing Settings. Add JVM CLI regression tests for invalid stack, trace, and parser-depth values, and preserve the boundary behavior that --max-trace 0 keeps a full trace and --max-parser-recursion-depth 0 still allows non-recursive expressions. Result: Invalid numeric CLI limits now fail before evaluation or parsing with user-facing CLI errors. Stack and trace behavior matches C++ jsonnet and go-jsonnet for shared flags, while the sjsonnet-specific parser-depth flag now rejects only the invalid negative range. References: C++ jsonnet cmd/jsonnet.cpp rejects --max-stack < 1 and --max-trace < 0. go-jsonnet cmd/jsonnet/cmd.go rejects --max-stack < 1 and --max-trace < 0. sjsonnet readme.md documents --max-parser-recursion-depth without a negative-value meaning.
8e83f97 to
fb74077
Compare
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.
Motivation:
sjsonnet accepted invalid numeric CLI limits.
--max-stack 0and--max-stack -1could still evaluate constant expressions, but the same settings make function-stack checks fail immediately once evaluation needs a stack frame.--max-trace -1entered evaluation and behaved as an undocumented full-trace setting.--max-parser-recursion-depth -1reached the parser and reportedParsing exceeded maximum recursion depth of -1instead of being rejected as an invalid CLI value.This is a CLI compatibility and input-validation issue rather than a Jsonnet language or stdlib semantics issue. C++ jsonnet and go-jsonnet both reject invalid values for the shared stack/trace flags during CLI parsing;
--max-parser-recursion-depthis sjsonnet-specific, so the other implementations have no comparable CLI flag. jrsonnet differs for--max-stack 0but rejects negative numeric values at its CLI parser.--exec 1 --max-stack 0ERROR: invalid --max-stack value: 0ERROR: invalid --max-stack value: 011ERROR: invalid --max-stack value: 0--exec 1 --max-stack -1ERROR: invalid --max-stack value: -1ERROR: invalid --max-stack value: -11ERROR: invalid --max-stack value: -1--exec "error \"x\"" --max-trace -1ERROR: invalid --max-trace value: -1ERROR: invalid --max-trace value: -1sjsonnet.Error: xERROR: invalid --max-trace value: -1--exec 1 --max-trace 011111--exec 1 --max-parser-recursion-depth -1Parsing exceeded maximum recursion depth of -1ERROR: invalid --max-parser-recursion-depth value: -1--exec 1 --max-parser-recursion-depth 011--exec "[1]" --max-parser-recursion-depth 0Parsing exceeded maximum recursion depth of 0Parsing exceeded maximum recursion depth of 0Modification:
Validate
--max-stack >= 1,--max-trace >= 0, and--max-parser-recursion-depth >= 0after CLI argument normalization and before constructingSettings. Add JVM CLI regression tests for--max-stack 0,--max-stack -1,--max-trace -1,--max-parser-recursion-depth -1, and the--max-parser-recursion-depth 0boundary.Result:
Invalid numeric CLI limits now fail before evaluation or parsing with user-facing CLI errors. The change matches C++ jsonnet and go-jsonnet for shared invalid stack/trace values, preserves documented
--max-trace 0full-trace behavior, and keeps the existing sjsonnet-specific--max-parser-recursion-depth 0boundary semantics.References:
cmd/jsonnet.cpprejects--max-stack < 1and--max-trace < 0.cmd/jsonnet/cmd.gorejects--max-stack < 1and--max-trace < 0.readme.mddocuments--max-parser-recursion-depthbut gives no negative-value semantics.