From 5e0d6d77b9b8bbdeb4a5356a0789b5332cdf6576 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Fri, 21 Apr 2023 13:46:56 +0400 Subject: [PATCH] core: check max file size before sending (#2224) --- src/Simplex/Chat.hs | 2 ++ src/Simplex/Chat/Controller.hs | 1 + src/Simplex/Chat/View.hs | 1 + 3 files changed, 4 insertions(+) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index d0ed3f3d92..240b09adad 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -59,6 +59,7 @@ import Simplex.Chat.ProfileGenerator (generateRandomProfile) import Simplex.Chat.Protocol import Simplex.Chat.Store import Simplex.Chat.Types +import Simplex.FileTransfer.Client.Main (maxFileSize) import Simplex.FileTransfer.Client.Presets (defaultXFTPServers) import Simplex.FileTransfer.Description (ValidFileDescription, gb, kb, mb) import Simplex.FileTransfer.Protocol (FileParty (..), FilePartyI) @@ -1596,6 +1597,7 @@ processChatCommand = \case ChatConfig {fileChunkSize, inlineFiles} <- asks config xftpCfg <- readTVarIO =<< asks userXFTPFileConfig fileSize <- getFileSize fsFilePath + when (fromInteger fileSize > maxFileSize) $ throwChatError $ CEFileSize f let chunks = - ((- fileSize) `div` fileChunkSize) fileInline = inlineFileMode mc inlineFiles chunks n fileMode = case xftpCfg of diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index b463ad65da..03f04166ed 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -783,6 +783,7 @@ data ChatErrorType | CEGroupCantResendInvitation {groupInfo :: GroupInfo, contactName :: ContactName} | CEGroupInternal {message :: String} | CEFileNotFound {message :: String} + | CEFileSize {filePath :: FilePath} | CEFileAlreadyReceiving {message :: String} | CEFileCancelled {message :: String} | CEFileCancel {fileId :: FileTransferId, message :: String} diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 33223f3ff6..5eedb8e638 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -1314,6 +1314,7 @@ viewChatError logLevel = \case CEGroupCantResendInvitation g c -> viewCannotResendInvitation g c CEGroupInternal s -> ["chat group bug: " <> plain s] CEFileNotFound f -> ["file not found: " <> plain f] + CEFileSize f -> ["file size exceeds the limit: " <> plain f] CEFileAlreadyReceiving f -> ["file is already being received: " <> plain f] CEFileCancelled f -> ["file cancelled: " <> plain f] CEFileCancel fileId e -> ["error cancelling file " <> sShow fileId <> ": " <> sShow e]