fix: add bounds check for star width/precision in std.format - #1090
Merged
stephenamar-db merged 1 commit intoJul 28, 2026
Merged
Conversation
Motivation:
`std.format("%*d", [5])` threw ArrayIndexOutOfBoundsException instead of
a clean error. The pre-loop bounds check ran before star consumption but
not after — once `*` width/precision consumed values and incremented `i`,
the subsequent `valuesArr.value(i)` had no guard. go-jsonnet and jrsonnet
both report "not enough values" cleanly; Python raises TypeError.
Modification:
Add `i >= valuesArr.length` guards after each `i += 1` in the three
star-consuming branches: (true,false), (false,true), and (true,true).
Error message matches the existing pre-loop check format.
Result:
Star format specs with insufficient values produce a clean user-facing
error ("too few values to format: N, expected at least M") instead of an
internal ArrayIndexOutOfBoundsException crash.
He-Pin
force-pushed
the
fix/format-star-spec-bounds-check
branch
from
July 27, 2026 19:04
66d49cc to
5446295
Compare
stephenamar-db
approved these changes
Jul 28, 2026
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
std.format("%*d", [5])threwArrayIndexOutOfBoundsExceptioninstead of a clean error. The bounds check at the top of the loop ran before star consumption but not after — once*width/precision consumed values and incrementedi, the subsequentvaluesArr.value(i)access had no guard.Both go-jsonnet and jrsonnet report a clean "not enough values" error. Python raises
TypeError: not enough arguments for format string.Modification
Add
i >= valuesArr.lengthguards after eachi += 1in the three star-consuming branches:(true,false),(false,true), and(true,true). The error message matches the existing pre-loop check format.Result
Star format specs with insufficient values now produce a clean user-facing error instead of an internal crash.
Behavior comparison
"%*d" % [5]"%*.*d" % [5, 3]"%*d" % [5, 42]" 42"" 42"" 42"" 42"" 42"(unchanged)"%*s" % []Test plan
std.format("%*d", [5])→ clean error instead of AIOOBEstd.format("%*.*d", [5, 3])→ clean error instead of AIOOBEstd.format("%*d", [5, 42])→" 42"(no regression)