Skip to content

Commit 7684e17

Browse files
committed
Do not read file if it is too large
1 parent f530856 commit 7684e17

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

routers/web/repo/editor.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,18 @@ func editFile(ctx *context.Context, isNewFile bool) {
164164
// Only some file types are editable online as text.
165165
ctx.Data["IsFileText"] = typesniffer.DetectContentType(buf).IsRepresentableAsText()
166166

167-
d, _ := io.ReadAll(dataRc)
168-
169-
buf = append(buf, d...)
170-
if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil {
171-
log.Error("ToUTF8: %v", err)
172-
ctx.Data["FileContent"] = string(buf)
167+
if blob.Size() >= setting.UI.MaxDisplayFileSize {
168+
ctx.Data["IsFileTooLarge"] = true
173169
} else {
174-
ctx.Data["FileContent"] = content
170+
d, _ := io.ReadAll(dataRc)
171+
172+
buf = append(buf, d...)
173+
if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil {
174+
log.Error("ToUTF8: %v", err)
175+
ctx.Data["FileContent"] = string(buf)
176+
} else {
177+
ctx.Data["FileContent"] = content
178+
}
175179
}
176180
} else {
177181
// Append filename from query, or empty string to allow username the new file.

0 commit comments

Comments
 (0)