Skip to content

Commit

Permalink
msgconv/from-whatsapp: validate animated sticker size before extracting
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 24, 2024
1 parent 6e98f25 commit 20f9786
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/msgconv/from-whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ func (mc *MessageConverter) reuploadWhatsAppAttachment(
if err != nil {
return nil, fmt.Errorf("failed to open animation.json: %w", err)
}
animationFileInfo, err := animationFile.Stat()
if err != nil {
_ = animationFile.Close()
return nil, fmt.Errorf("failed to stat animation.json: %w", err)
} else if animationFileInfo.Size() > uploadFileThreshold {
_ = animationFile.Close()
return nil, fmt.Errorf("animation.json is too large (%.2f MiB)", float64(animationFileInfo.Size())/1024/1024)
}
data, err = io.ReadAll(animationFile)
_ = animationFile.Close()
if err != nil {
Expand Down

0 comments on commit 20f9786

Please sign in to comment.