Cap tokens per Ruby file
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful

This commit is contained in:
2026-11-08 18:54:44 +11:00
parent 0edce80e2c
commit 71425b58c8
2 changed files with 9 additions and 3 deletions
+2 -2
View File
@@ -464,7 +464,7 @@ func TestStepBudget(t *testing.T) {
func TestDeepNestingIsAnError(t *testing.T) {
if os.Getenv("GENTYPES_DEEP_CHILD") == "1" {
_, err := parseFile("Puppet::Type.newtype(:t) do\n newparam(:a) do\n newvalues("+strings.Repeat("[", 4<<20)+"\n", nil)
if err == nil || !strings.Contains(err.Error(), "nesting deeper than") {
if err == nil || !strings.Contains(err.Error(), "more than 262144 tokens") {
os.Exit(3)
}
return
@@ -482,7 +482,7 @@ func TestDeepNestingIsAnError(t *testing.T) {
cmd := exec.Command(os.Args[0], "-test.run=^TestDeepNestingIsAnError$")
cmd.Env = append(os.Environ(), "GENTYPES_DEEP_CHILD=1")
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("4MiB of '[' must be a parse error: %v\n%.300s", err, out)
t.Fatalf("4MiB of '[' must hit the token cap: %v\n%.300s", err, out)
}
}
+7 -1
View File
@@ -7,7 +7,10 @@ import (
"unicode/utf8"
)
const maxDepth = 256
const (
maxDepth = 256
maxTokens = 1 << 18
)
type kind int
@@ -173,6 +176,9 @@ func (l *lexer) run() error {
continue
}
start := len(l.toks)
if start > maxTokens {
return fmt.Errorf("more than %d tokens", maxTokens)
}
if err := l.next(space); err != nil {
return err
}