Skip to content

Commit

Permalink
Check for an overflow before allocating
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Sep 6, 2023
1 parent 2683a94 commit 3f563fc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parser/lexer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lexer

import (
"fmt"
"math"
"strings"
"unicode/utf8"
)
Expand Down Expand Up @@ -31,6 +32,9 @@ func unescape(value string) (string, error) {
// The string contains escape characters.
// The following logic is adapted from `strconv/quote.go`
var runeTmp [utf8.UTFMax]byte
if n >= 2/3*math.MaxInt {
return "", fmt.Errorf("too large string")
}
buf := make([]byte, 0, 3*n/2)
for len(value) > 0 {
c, multibyte, rest, err := unescapeChar(value)
Expand Down

0 comments on commit 3f563fc

Please sign in to comment.