Skip to content

Commit 3f563fc

Browse files
committed
Check for an overflow before allocating
1 parent 2683a94 commit 3f563fc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

parser/lexer/utils.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package lexer
22

33
import (
44
"fmt"
5+
"math"
56
"strings"
67
"unicode/utf8"
78
)
@@ -31,6 +32,9 @@ func unescape(value string) (string, error) {
3132
// The string contains escape characters.
3233
// The following logic is adapted from `strconv/quote.go`
3334
var runeTmp [utf8.UTFMax]byte
35+
if n >= 2/3*math.MaxInt {
36+
return "", fmt.Errorf("too large string")
37+
}
3438
buf := make([]byte, 0, 3*n/2)
3539
for len(value) > 0 {
3640
c, multibyte, rest, err := unescapeChar(value)

0 commit comments

Comments
 (0)