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:
parent
1bd789df4e
commit
8696be2b25
@ -1,6 +1,7 @@
|
|||||||
package imagemeta
|
package imagemeta
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"io"
|
"io"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -24,6 +25,8 @@ func IsSVG(r io.Reader) (bool, error) {
|
|||||||
buf := make([]byte, 0, maxBytes)
|
buf := make([]byte, 0, maxBytes)
|
||||||
b := make([]byte, 1024)
|
b := make([]byte, 1024)
|
||||||
|
|
||||||
|
rr := bytes.NewReader(buf)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
n, err := r.Read(b)
|
n, err := r.Read(b)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
@ -34,8 +37,11 @@ func IsSVG(r io.Reader) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf = append(buf, b[:n]...)
|
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
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user