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 MaxTaskErrorItemsCount = 3
|
||||||
|
const MaxImportFileSizeBytes = 52428800
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNoChannelData = errors.New("No channels to import messages from")
|
ErrNoChannelData = errors.New("No channels to import messages from")
|
||||||
ErrNoMessageData = errors.New("No messages to import")
|
ErrNoMessageData = errors.New("No messages to import")
|
||||||
ErrMarshalMessage = errors.New("Couldn't marshal discord message")
|
ErrMarshalMessage = errors.New("Couldn't marshal discord message")
|
||||||
|
ErrImportFileTooBig = fmt.Errorf("File is too big (max. %d MB)", MaxImportFileSizeBytes/1024/1024)
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageType string
|
type MessageType string
|
||||||
|
|
|
@ -2233,6 +2233,19 @@ func (m *Messenger) ExtractDiscordDataFromImportFiles(filesToImport []string) (*
|
||||||
|
|
||||||
for _, fileToImport := range filesToImport {
|
for _, fileToImport := range filesToImport {
|
||||||
filePath := strings.Replace(fileToImport, "file://", "", -1)
|
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)
|
bytes, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors[fileToImport] = discord.Error(err.Error())
|
errors[fileToImport] = discord.Error(err.Error())
|
||||||
|
|
Loading…
Reference in New Issue