fix(DiscordImport): don't allow imports of files bigger than 50 MB

See https://github.com/status-im/status-desktop/issues/9261 for more info
This commit is contained in:
Pascal Precht 2023-01-24 10:36:07 +01:00 committed by r4bbit
parent bfe9307f1f
commit efbad4e9bc
2 changed files with 18 additions and 3 deletions

View File

@ -18,11 +18,13 @@ const (
)
const MaxTaskErrorItemsCount = 3
const MaxImportFileSizeBytes = 52428800
var (
ErrNoChannelData = errors.New("No channels to import messages from")
ErrNoMessageData = errors.New("No messages to import")
ErrMarshalMessage = errors.New("Couldn't marshal discord message")
ErrImportFileTooBig = fmt.Errorf("File is too big (max. %d MB)", MaxImportFileSizeBytes/1024/1024)
)
type MessageType string

View File

@ -2233,6 +2233,19 @@ func (m *Messenger) ExtractDiscordDataFromImportFiles(filesToImport []string) (*
for _, fileToImport := range filesToImport {
filePath := strings.Replace(fileToImport, "file://", "", -1)
fileInfo, err := os.Stat(filePath)
if err != nil {
errors[fileToImport] = discord.Error(err.Error())
continue
}
fileSize := fileInfo.Size()
if fileSize > discord.MaxImportFileSizeBytes {
errors[fileToImport] = discord.Error(discord.ErrImportFileTooBig.Error())
continue
}
bytes, err := os.ReadFile(filePath)
if err != nil {
errors[fileToImport] = discord.Error(err.Error())