Cap tokens per Ruby file
This commit is contained in:
@@ -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,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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user