mirror of
https://github.com/minio/minio.git
synced 2025-11-10 05:59:43 -05:00
Limit jstream parse depth (#20474)
Add https://github.com/bcicen/jstream/pull/15 by vendoring the package. Sets JSON depth limit to 100 entries in S3 Select.
This commit is contained in:
44
internal/s3select/jstream/scratch.go
Normal file
44
internal/s3select/jstream/scratch.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package jstream
|
||||
|
||||
import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type scratch struct {
|
||||
data []byte
|
||||
fill int
|
||||
}
|
||||
|
||||
// reset scratch buffer
|
||||
func (s *scratch) reset() { s.fill = 0 }
|
||||
|
||||
// bytes returns the written contents of scratch buffer
|
||||
func (s *scratch) bytes() []byte { return s.data[0:s.fill] }
|
||||
|
||||
// grow scratch buffer
|
||||
func (s *scratch) grow() {
|
||||
ndata := make([]byte, cap(s.data)*2)
|
||||
copy(ndata, s.data)
|
||||
s.data = ndata
|
||||
}
|
||||
|
||||
// append single byte to scratch buffer
|
||||
func (s *scratch) add(c byte) {
|
||||
if s.fill+1 >= cap(s.data) {
|
||||
s.grow()
|
||||
}
|
||||
|
||||
s.data[s.fill] = c
|
||||
s.fill++
|
||||
}
|
||||
|
||||
// append encoded rune to scratch buffer
|
||||
func (s *scratch) addRune(r rune) int {
|
||||
if s.fill+utf8.UTFMax >= cap(s.data) {
|
||||
s.grow()
|
||||
}
|
||||
|
||||
n := utf8.EncodeRune(s.data[s.fill:], r)
|
||||
s.fill += n
|
||||
return n
|
||||
}
|
||||
Reference in New Issue
Block a user