From c326369f471c38053b12e04555ddc3c3ee44d484 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Thu, 22 Jan 2026 08:23:00 +0800 Subject: [PATCH] Allow foreachref parse max tokens from 4*64KB to 4MB (#36414) (#36429) Backport #36414 by @lunny Fix #36408 Signed-off-by: Lunny Xiao Co-authored-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 ebdc7344d0..4e88e9430d 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.