[librsvg: 1/2] (#548): Support images with data: URLs that don't have a MIME-type



commit 1f2e310e1b526b487981e6ba56f173f137952746
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Mar 27 19:11:18 2020 -0600

    (#548): Support images with data: URLs that don't have a MIME-type
    
    This is to be resilient with Open Clip Art images generated by
    an (old?) version of Adobe Illustrator, which creates data: URLs without
    a MIME-type.  We'll sniff those images instead of using text/plain.
    
    https://gitlab.gnome.org/GNOME/librsvg/-/issues/548

 rsvg_internals/src/document.rs                             |  11 ++++++++++-
 .../reftests/bugs/548-data-url-without-mimetype-ref.png    | Bin 0 -> 77 bytes
 .../reftests/bugs/548-data-url-without-mimetype.svg        |   6 ++++++
 3 files changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/rsvg_internals/src/document.rs b/rsvg_internals/src/document.rs
index 23a5ccf4..a3db4a91 100644
--- a/rsvg_internals/src/document.rs
+++ b/rsvg_internals/src/document.rs
@@ -205,13 +205,22 @@ fn load_image(
 ) -> Result<SharedImageSurface, LoadingError> {
     let BinaryData {
         data: bytes,
-        content_type,
+        mut content_type,
     } = io::acquire_data(&aurl, None)?;
 
     if bytes.is_empty() {
         return Err(LoadingError::EmptyData);
     }
 
+    // See issue #548 - data: URLs without a MIME-type automatically
+    // fall back to "text/plain;charset=US-ASCII".  Some (old?) versions of
+    // Adobe Illustrator generate data: URLs without MIME-type for image
+    // data.  We'll catch this and fall back to sniffing by unsetting the
+    // content_type.
+    if content_type.as_ref().map(String::as_str) == Some("text/plain;charset=US-ASCII") {
+        content_type = None;
+    }
+
     let loader = if let Some(ref content_type) = content_type {
         PixbufLoader::new_with_mime_type(content_type)?
     } else {
diff --git a/tests/fixtures/reftests/bugs/548-data-url-without-mimetype-ref.png 
b/tests/fixtures/reftests/bugs/548-data-url-without-mimetype-ref.png
new file mode 100644
index 00000000..9008274a
Binary files /dev/null and b/tests/fixtures/reftests/bugs/548-data-url-without-mimetype-ref.png differ
diff --git a/tests/fixtures/reftests/bugs/548-data-url-without-mimetype.svg 
b/tests/fixtures/reftests/bugs/548-data-url-without-mimetype.svg
new file mode 100644
index 00000000..f2cd71c7
--- /dev/null
+++ b/tests/fixtures/reftests/bugs/548-data-url-without-mimetype.svg
@@ -0,0 +1,6 @@
+<svg xmlns="http://www.w3.org/2000/svg";
+     xmlns:xlink="http://www.w3.org/1999/xlink"; width="10" height="10">
+  <image
+      
xlink:href="data:;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAFElEQVQY02Nk+M+ABzAxMIxKYwIAQC0BEwZFOw4AAAAASUVORK5CYII="
+      x="0" y="0" width="10" height="10"/>
+</svg>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]