core: check max file size before sending (#2224)

This commit is contained in:
spaced4ndy
2023-04-21 13:46:56 +04:00
committed by GitHub
parent a06393f520
commit 5e0d6d77b9
3 changed files with 4 additions and 0 deletions
+2
View File
@@ -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
+1
View File
@@ -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}
+1
View File
@@ -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]