Skip to content

Commit 968f23d

Browse files
LinkinStarsshuashuaikelvinkuohgaolsy-records
authored
Release/1.2.5 (#761)
Signed-off-by: Adam Vollrath <[email protected]> Co-authored-by: shuai <[email protected]> Co-authored-by: kelvinkuo <[email protected]> Co-authored-by: hgaol <[email protected]> Co-authored-by: sy-records <[email protected]> Co-authored-by: Adam Vollrath <[email protected]> Co-authored-by: kumfo <[email protected]> Co-authored-by: Yang Wong <yang wang> Co-authored-by: hbsciw <[email protected]>
1 parent abecc1c commit 968f23d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pkg/checker/file_type.go

+32
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,53 @@ import (
2929
"strings"
3030
)
3131

32+
const (
33+
maxImageSize = 8192 * 8192
34+
)
35+
3236
// IsSupportedImageFile currently answers support image type is
3337
// `image/jpeg, image/jpg, image/png, image/gif, image/webp`
3438
func IsSupportedImageFile(file io.Reader, ext string) bool {
3539
ext = strings.ToLower(strings.TrimPrefix(ext, "."))
3640
var err error
3741
switch ext {
3842
case "jpg", "jpeg", "png", "gif": // only allow for `image/jpeg,image/jpg,image/png, image/gif`
43+
if !checkImageSize(file) {
44+
return false
45+
}
3946
_, _, err = image.Decode(file)
4047
case "ico":
4148
// TODO: There is currently no good Golang library to parse whether the image is in ico format.
4249
return true
4350
case "webp":
51+
if !checkWebpSize(file) {
52+
return false
53+
}
4454
_, err = webp.Decode(file)
4555
default:
4656
return false
4757
}
4858
return err == nil
4959
}
60+
61+
func checkImageSize(file io.Reader) bool {
62+
config, _, err := image.DecodeConfig(file)
63+
if err != nil {
64+
return false
65+
}
66+
if (config.Width * config.Height) > maxImageSize {
67+
return false
68+
}
69+
return true
70+
}
71+
72+
func checkWebpSize(file io.Reader) bool {
73+
config, err := webp.DecodeConfig(file)
74+
if err != nil {
75+
return false
76+
}
77+
if (config.Width * config.Height) > maxImageSize {
78+
return false
79+
}
80+
return true
81+
}

0 commit comments

Comments
 (0)