1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00

Fix dtection of non-strict SVGs

This commit is contained in:
DarthSim 2020-09-22 18:03:05 +06:00
parent 1bd789df4e
commit 8696be2b25

View File

@ -1,6 +1,7 @@
package imagemeta
import (
"bytes"
"encoding/xml"
"io"
"sync/atomic"
@ -24,6 +25,8 @@ func IsSVG(r io.Reader) (bool, error) {
buf := make([]byte, 0, maxBytes)
b := make([]byte, 1024)
rr := bytes.NewReader(buf)
for {
n, err := r.Read(b)
if err != nil && err != io.EOF {
@ -34,8 +37,11 @@ func IsSVG(r io.Reader) (bool, error) {
}
buf = append(buf, b[:n]...)
rr.Reset(buf)
if xml.Unmarshal(buf, &h); h.XMLName.Local == "svg" {
dec := xml.NewDecoder(rr)
dec.Strict = false
if dec.Decode(&h); h.XMLName.Local == "svg" {
return true, nil
}