You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/01/29 11:14:17 UTC

(incubator-answer) branch main updated: Release/1.2.5 (#761)

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/main by this push:
     new 968f23db Release/1.2.5 (#761)
968f23db is described below

commit 968f23db7ff920b29793589c8a3ba7e8eb402695
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Mon Jan 29 19:14:13 2024 +0800

    Release/1.2.5 (#761)
    
    Signed-off-by: Adam Vollrath <ad...@gmail.com>
    Co-authored-by: shuai <li...@sifou.com>
    Co-authored-by: kelvinkuo <ke...@gmail.com>
    Co-authored-by: hgaol <dh...@hotmail.com>
    Co-authored-by: sy-records <52...@qq52o.cn>
    Co-authored-by: Adam Vollrath <ad...@gmail.com>
    Co-authored-by: kumfo <ku...@sifou.com>
    Co-authored-by: Yang Wong <yang wang>
    Co-authored-by: hbsciw <hb...@gmail.com>
---
 pkg/checker/file_type.go | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/pkg/checker/file_type.go b/pkg/checker/file_type.go
index cabd5883..3599270a 100644
--- a/pkg/checker/file_type.go
+++ b/pkg/checker/file_type.go
@@ -29,6 +29,10 @@ import (
 	"strings"
 )
 
+const (
+	maxImageSize = 8192 * 8192
+)
+
 // IsSupportedImageFile currently answers support image type is
 // `image/jpeg, image/jpg, image/png, image/gif, image/webp`
 func IsSupportedImageFile(file io.Reader, ext string) bool {
@@ -36,14 +40,42 @@ func IsSupportedImageFile(file io.Reader, ext string) bool {
 	var err error
 	switch ext {
 	case "jpg", "jpeg", "png", "gif": // only allow for `image/jpeg,image/jpg,image/png, image/gif`
+		if !checkImageSize(file) {
+			return false
+		}
 		_, _, err = image.Decode(file)
 	case "ico":
 		// TODO: There is currently no good Golang library to parse whether the image is in ico format.
 		return true
 	case "webp":
+		if !checkWebpSize(file) {
+			return false
+		}
 		_, err = webp.Decode(file)
 	default:
 		return false
 	}
 	return err == nil
 }
+
+func checkImageSize(file io.Reader) bool {
+	config, _, err := image.DecodeConfig(file)
+	if err != nil {
+		return false
+	}
+	if (config.Width * config.Height) > maxImageSize {
+		return false
+	}
+	return true
+}
+
+func checkWebpSize(file io.Reader) bool {
+	config, err := webp.DecodeConfig(file)
+	if err != nil {
+		return false
+	}
+	if (config.Width * config.Height) > maxImageSize {
+		return false
+	}
+	return true
+}