]> Cypherpunks.ru repositories - gostls13.git/commitdiff
regexp: add ErrLarge error
authorcuiweixie <cuiweixie@gmail.com>
Sat, 22 Oct 2022 14:07:07 +0000 (22:07 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 2 Nov 2022 18:15:21 +0000 (18:15 +0000)
For #56041

Change-Id: I6c98458b5c0d3b3636a53ee04fc97221f3fd8bbc
Reviewed-on: https://go-review.googlesource.com/c/go/+/444817
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: xie cui <523516579@qq.com>

api/next/56041.txt [new file with mode: 0644]
src/regexp/all_test.go
src/regexp/syntax/parse.go

diff --git a/api/next/56041.txt b/api/next/56041.txt
new file mode 100644 (file)
index 0000000..19cb164
--- /dev/null
@@ -0,0 +1,2 @@
+pkg regexp/syntax, const ErrLarge = "expression too large" #56041
+pkg regexp/syntax, const ErrLarge ErrorCode #56041
index c233cfa9eaac75fb1f33de6db2aa3b53887a9177..52de3fef83da514f25f404072e7cb8ce8f0a13da 100644 (file)
@@ -49,6 +49,7 @@ var badRe = []stringError{
        {`a**`, "invalid nested repetition operator: `**`"},
        {`a*+`, "invalid nested repetition operator: `*+`"},
        {`\x`, "invalid escape sequence: `\\x`"},
+       {strings.Repeat(`\pL`, 27000), "expression too large"},
 }
 
 func compileTest(t *testing.T, expr string, error string) *Regexp {
index 092dcfd5d052d3af40d2c78767820e695809638d..accee9ab089edc1c78a9b7ed3eb00d6a0cc4167b 100644 (file)
@@ -44,6 +44,7 @@ const (
        ErrTrailingBackslash     ErrorCode = "trailing backslash at end of expression"
        ErrUnexpectedParen       ErrorCode = "unexpected )"
        ErrNestingDepth          ErrorCode = "expression nests too deeply"
+       ErrLarge                 ErrorCode = "expression too large"
 )
 
 func (e ErrorCode) String() string {
@@ -159,7 +160,7 @@ func (p *parser) reuse(re *Regexp) {
 
 func (p *parser) checkLimits(re *Regexp) {
        if p.numRunes > maxRunes {
-               panic(ErrInternalError)
+               panic(ErrLarge)
        }
        p.checkSize(re)
        p.checkHeight(re)
@@ -203,7 +204,7 @@ func (p *parser) checkSize(re *Regexp) {
        }
 
        if p.calcSize(re, true) > maxSize {
-               panic(ErrInternalError)
+               panic(ErrLarge)
        }
 }
 
@@ -897,8 +898,8 @@ func parse(s string, flags Flags) (_ *Regexp, err error) {
                        panic(r)
                case nil:
                        // ok
-               case ErrInternalError: // too big
-                       err = &Error{Code: ErrInternalError, Expr: s}
+               case ErrLarge: // too big
+                       err = &Error{Code: ErrLarge, Expr: s}
                case ErrNestingDepth:
                        err = &Error{Code: ErrNestingDepth, Expr: s}
                }