Skip to content

Commit d46021a

Browse files
lunnylafrikswxiaoguang
authored
Allow foreachref parse max tokens from 4*64KB to 4MB (#36414)
Fix #36408 --------- Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 9ea91e0 commit d46021a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

modules/git/foreachref/parser.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ type Parser struct {
3030
func NewParser(r io.Reader, format Format) *Parser {
3131
scanner := bufio.NewScanner(r)
3232

33-
// default MaxScanTokenSize = 64 kiB may be too small for some references,
34-
// so allow the buffer to grow up to 4x if needed
35-
scanner.Buffer(nil, 4*bufio.MaxScanTokenSize)
33+
// default Scanner.MaxScanTokenSize = 64 kiB may be too small for some references,
34+
// so allow the buffer to be large enough in case the ref has long content (e.g.: a tag with long message)
35+
// as long as it doesn't exceed some reasonable limit (4 MiB here, or MAX_DISPLAY_FILE_SIZE=8MiB), it is OK
36+
// there are still some choices: 1. add a config option for the limit; 2. don't use scanner and write our own parser to fully handle large contents
37+
scanner.Buffer(nil, 4*1024*1024)
3638

3739
// in addition to the reference delimiter we specified in the --format,
3840
// `git for-each-ref` will always add a newline after every reference.

0 commit comments

Comments
 (0)