From e19d0e4f563332450d5da1287abf0bca32f04a71 Mon Sep 17 00:00:00 2001 From: Fabian Meyer Date: Thu, 28 Aug 2025 12:18:54 +0200 Subject: [PATCH] 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 Co-authored-by: wxiaoguang --- modules/git/foreachref/parser.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/git/foreachref/parser.go b/modules/git/foreachref/parser.go index de69eaa2c8..ebdc7344d0 100644 --- a/modules/git/foreachref/parser.go +++ b/modules/git/foreachref/parser.go @@ -30,6 +30,10 @@ type Parser struct { func NewParser(r io.Reader, format Format) *Parser { 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, // `git for-each-ref` will always add a newline after every reference. 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" } func (p *Parser) Next() map[string]string { if !p.scanner.Scan() { + if err := p.scanner.Err(); err != nil { + p.err = err + } return nil } fields, err := p.parseRef(p.scanner.Text())