shithub: mycel

Download patch

ref: 3d58c884fa97567ebb1b8b47bc8ceb8c75b2f680
parent: 8bd61f88172581a0af0ea5f2293bff43f011eb1b
author: Philip Silva <philip.silva@protonmail.com>
date: Sun Mar 28 05:15:00 EDT 2021

Fix crash on incomplete data uri

--- a/img/img.go
+++ b/img/img.go
@@ -36,7 +36,6 @@
 	parts := strings.Split(addr, ",")
 	
 	var ctStr string
-
 	if strings.Contains(parts[0], ";") {
 		header := strings.Split(parts[0], ";")
 		ctStr = header[0]
@@ -46,7 +45,10 @@
 	if ct, err = opossum.NewContentType(ctStr, nil); err != nil {
 		return nil, ct, fmt.Errorf("content type: %v: %w", ctStr, err)
 	}
-	
+
+	if len(parts) == 1 {
+		return nil, ct, fmt.Errorf("empty: %v", addr)
+	}
 	if strings.Contains(addr, "base64") {
 		e := base64.RawStdEncoding
 		if strings.HasSuffix(addr, "=") {
--- a/img/img_test.go
+++ b/img/img_test.go
@@ -31,6 +31,14 @@
 	}
 }
 
+func TestEmpty(t *testing.T) {
+	src := "data:image/svg+xml"
+	_, _, err := parseDataUri(src)
+	if err == nil {
+		t.Fatalf(err.Error())
+	}
+}
+
 func TestSvg(t *testing.T) {
        xml := `
                <svg fill="currentColor" height="24" viewBox="0 0 24 24" width="24">