浏览代码

Merge branch 'master' into version/4

DarthSim 4 周之前
父节点
当前提交
bc9d16a622
共有 2 个文件被更改,包括 17 次插入16 次删除
  1. 1 0
      CHANGELOG.md
  2. 16 16
      svg/svg.go

+ 1 - 0
CHANGELOG.md

@@ -17,6 +17,7 @@
 - Fix `X-Origin-Height` and `X-Result-Height` debug header values for animated images.
 - Fix keeping copyright info in EXIF.
 - Fix preserving color profiles in TIFF images.
+- Fix freezes during sanitization or minification of some broken SVGs.
 - (pro) Fix generating thumbnails for VP9 videos with high bit depth.
 - (pro) Fix `IMGPROXY_CUSTOM_RESPONSE_HEADERS` and `IMGPROXY_RESPONSE_HEADERS_PASSTHROUGH` configs behavior when the `raw` processing option is used.
 

+ 16 - 16
svg/svg.go

@@ -41,11 +41,16 @@ func Sanitize(data imagedata.ImageData) (imagedata.ImageData, error) {
 	for {
 		tt, tdata := l.Next()
 
-		if ignoreTag > 0 {
-			switch tt {
-			case xml.ErrorToken:
+		if tt == xml.ErrorToken {
+			if l.Err() != io.EOF {
 				cancel()
 				return nil, newSanitizeError(l.Err())
+			}
+			break
+		}
+
+		if ignoreTag > 0 {
+			switch tt {
 			case xml.EndTagToken, xml.StartTagCloseVoidToken:
 				ignoreTag--
 			case xml.StartTagToken:
@@ -56,19 +61,6 @@ func Sanitize(data imagedata.ImageData) (imagedata.ImageData, error) {
 		}
 
 		switch tt {
-		case xml.ErrorToken:
-			if l.Err() != io.EOF {
-				cancel()
-				return nil, newSanitizeError(l.Err())
-			}
-
-			newData := imagedata.NewFromBytesWithFormat(
-				imagetype.SVG,
-				buf.Bytes(),
-			)
-			newData.AddCancel(cancel)
-
-			return newData, nil
 		case xml.StartTagToken:
 			curTagName = strings.ToLower(string(l.Text()))
 
@@ -97,4 +89,12 @@ func Sanitize(data imagedata.ImageData) (imagedata.ImageData, error) {
 			buf.Write(tdata)
 		}
 	}
+
+	newData := imagedata.NewFromBytesWithFormat(
+		imagetype.SVG,
+		buf.Bytes(),
+	)
+	newData.AddCancel(cancel)
+
+	return newData, nil
 }