From 2331a2c9702f082bf8d34c8d76fc810e6a7efa20 Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Wed, 26 Nov 2025 15:25:59 +0530 Subject: [PATCH] add validation for empty file uploads with appropriate error message --- cmd/media.go | 6 ++++++ i18n/en.json | 1 + 2 files changed, 7 insertions(+) diff --git a/cmd/media.go b/cmd/media.go index cfb031b8..426764dd 100644 --- a/cmd/media.go +++ b/cmd/media.go @@ -66,6 +66,12 @@ func handleMediaUpload(r *fastglue.Request) error { srcFileSize := fileHeader.Size srcExt := strings.TrimPrefix(strings.ToLower(filepath.Ext(srcFileName)), ".") + // Check if file is empty + if srcFileSize == 0 { + app.lo.Error("error: uploaded file is empty (0 bytes)") + return r.SendErrorEnvelope(fasthttp.StatusBadRequest, app.i18n.T("media.fileEmpty"), nil, envelope.InputError) + } + // Check file size consts := app.consts.Load().(*constants) if bytesToMegabytes(srcFileSize) > float64(consts.MaxFileUploadSizeMB) { diff --git a/i18n/en.json b/i18n/en.json index ca49201e..c631af1e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -332,6 +332,7 @@ "user.errorGeneratingPasswordToken": "Error generating password token", "media.fileSizeTooLarge": "File size too large, please upload a file less than {size} ", "media.fileTypeNotAllowed": "File type not allowed", + "media.fileEmpty": "This file is 0 bytes, so it will not be attached.", "inbox.emptyIMAP": "Empty IMAP config", "inbox.emptySMTP": "Empty SMTP config", "template.defaultTemplateAlreadyExists": "Default template already exists",