From d46021a83ad511ef2df8050cb6f2f4076ee366ba Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 20 Jan 2026 20:18:57 -0800 Subject: [PATCH] Allow foreachref parse max tokens from 4*64KB to 4MB (#36414) Fix #36408 --------- Signed-off-by: Lunny Xiao Co-authored-by: Lauris BH Co-authored-by: wxiaoguang --- modules/git/foreachref/parser.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/git/foreachref/parser.go b/modules/git/foreachref/parser.go index fa2ef316c7..913431795f 100644 --- a/modules/git/foreachref/parser.go +++ b/modules/git/foreachref/parser.go @@ -30,9 +30,11 @@ 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) + // default Scanner.MaxScanTokenSize = 64 kiB may be too small for some references, + // so allow the buffer to be large enough in case the ref has long content (e.g.: a tag with long message) + // as long as it doesn't exceed some reasonable limit (4 MiB here, or MAX_DISPLAY_FILE_SIZE=8MiB), it is OK + // 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 + scanner.Buffer(nil, 4*1024*1024) // in addition to the reference delimiter we specified in the --format, // `git for-each-ref` will always add a newline after every reference.