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:
parent
bfe9307f1f
commit
efbad4e9bc
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue