From af29b8182c87428de452a889303aa948fd4d40fc Mon Sep 17 00:00:00 2001 From: Giteabot Date: Wed, 25 Mar 2026 01:18:01 +0800 Subject: [PATCH] Catch scanner error when possible to avoid bypass (#36963) (#36976) Backport #36963 by @lunny Co-authored-by: Lunny Xiao --- cmd/hook.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/hook.go b/cmd/hook.go index 9aeabe61ed..2b5e38f945 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -276,6 +276,9 @@ Gitea or set your environment appropriately.`, "") lastline = 0 } } + if err := scanner.Err(); err != nil { + return fail(ctx, "Hook failed: stdin read error", "scanner error: %v", err) + } if count > 0 { hookOptions.OldCommitIDs = oldCommitIDs[:count] @@ -415,6 +418,11 @@ Gitea or set your environment appropriately.`, "") count = 0 } } + if err := scanner.Err(); err != nil { + _ = dWriter.Close() + hookPrintResults(results) + return fail(ctx, "Hook failed: stdin read error", "scanner error: %v", err) + } if count == 0 { if wasEmpty && masterPushed {