From 7684e1720d980161ec61c7e126455689df50c3fa Mon Sep 17 00:00:00 2001 From: bytedream Date: Sat, 3 May 2025 01:43:26 +0200 Subject: [PATCH] Do not read file if it is too large --- routers/web/repo/editor.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 81c2cd8e69..394a3548cf 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -164,14 +164,18 @@ func editFile(ctx *context.Context, isNewFile bool) { // Only some file types are editable online as text. ctx.Data["IsFileText"] = typesniffer.DetectContentType(buf).IsRepresentableAsText() - d, _ := io.ReadAll(dataRc) - - buf = append(buf, d...) - if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil { - log.Error("ToUTF8: %v", err) - ctx.Data["FileContent"] = string(buf) + if blob.Size() >= setting.UI.MaxDisplayFileSize { + ctx.Data["IsFileTooLarge"] = true } else { - ctx.Data["FileContent"] = content + d, _ := io.ReadAll(dataRc) + + buf = append(buf, d...) + if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil { + log.Error("ToUTF8: %v", err) + ctx.Data["FileContent"] = string(buf) + } else { + ctx.Data["FileContent"] = content + } } } else { // Append filename from query, or empty string to allow username the new file.