1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-29 12:58:29 +00:00

Allow foreachref parser to grow its buffer (#35365)

Fixes #35221, let the scanner's buffer grow up to 4x (256 kiB), and add an error check

---------

Signed-off-by: Fabian Meyer <fabian.meyer@lawo.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Fabian Meyer
2025-08-28 12:18:54 +02:00
committed by GitHub
parent dca1af7cad
commit e19d0e4f56

View File

@@ -30,6 +30,10 @@ type Parser struct {
func NewParser(r io.Reader, format Format) *Parser { func NewParser(r io.Reader, format Format) *Parser {
scanner := bufio.NewScanner(r) scanner := bufio.NewScanner(r)
// default MaxScanTokenSize = 64 kiB may be too small for some references,
// so allow the buffer to grow up to 4x if needed
scanner.Buffer(nil, 4*bufio.MaxScanTokenSize)
// in addition to the reference delimiter we specified in the --format, // in addition to the reference delimiter we specified in the --format,
// `git for-each-ref` will always add a newline after every reference. // `git for-each-ref` will always add a newline after every reference.
refDelim := make([]byte, 0, len(format.refDelim)+1) refDelim := make([]byte, 0, len(format.refDelim)+1)
@@ -70,6 +74,9 @@ func NewParser(r io.Reader, format Format) *Parser {
// { "objecttype": "tag", "refname:short": "v1.16.4", "object": "f460b7543ed500e49c133c2cd85c8c55ee9dbe27" } // { "objecttype": "tag", "refname:short": "v1.16.4", "object": "f460b7543ed500e49c133c2cd85c8c55ee9dbe27" }
func (p *Parser) Next() map[string]string { func (p *Parser) Next() map[string]string {
if !p.scanner.Scan() { if !p.scanner.Scan() {
if err := p.scanner.Err(); err != nil {
p.err = err
}
return nil return nil
} }
fields, err := p.parseRef(p.scanner.Text()) fields, err := p.parseRef(p.scanner.Text())