[librsvg/librsvg-2.44] (#349): Don't panic if we get a "data:" URI with empty data.



commit 6818de0219848e982428f44b5af6eb7157aaf570
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Oct 1 09:28:46 2018 -0500

    (#349): Don't panic if we get a "data:" URI with empty data.
    
    _rsvg_handle_acquire_data() can return NULL and data_len = 0 with a
    NULL error, in the case where the decoded data is empty.  Previously
    we assummed that its return value being NULL always meant that an
    underlying error had happened.
    
    https://gitlab.gnome.org/GNOME/librsvg/issues/349

 librsvg/rsvg-handle.c                       | 12 +++++++++++-
 rsvg_internals/src/handle.rs                |  9 ++++++++-
 tests/fixtures/crash/349-empty-data-uri.svg |  1 +
 3 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index b500f3ae..7de1e400 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -1731,9 +1731,19 @@ rsvg_cairo_surface_new_from_href (RsvgHandle *handle,
     GdkPixbuf *pixbuf = NULL;
     cairo_surface_t *surface = NULL;
 
+    g_assert (error != NULL && *error == NULL);
+
     data = _rsvg_handle_acquire_data (handle, href, &mime_type, &data_len, error);
-    if (data == NULL)
+    if (data == NULL) {
+        if (*error == NULL && data_len == 0) {
+            g_set_error (error,
+                         RSVG_ERROR,
+                         RSVG_ERROR_FAILED,
+                         "empty image data");
+        }
+
         return NULL;
+    }
 
     if (mime_type) {
         loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, error);
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index f75492e5..30333634 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -85,7 +85,14 @@ pub fn acquire_data(handle: *mut RsvgHandle, url: &str) -> Result<BinaryData, gl
         );
 
         if buf.is_null() {
-            Err(from_glib_full(error))
+            if error.is_null() && len == 0 {
+                Ok(BinaryData {
+                    data: Vec::new(),
+                    content_type: None,
+                })
+            } else {
+                Err(from_glib_full(error))
+            }
         } else {
             Ok(BinaryData {
                 data: FromGlibContainer::from_glib_full_num(buf as *mut u8, len),
diff --git a/tests/fixtures/crash/349-empty-data-uri.svg b/tests/fixtures/crash/349-empty-data-uri.svg
new file mode 100644
index 00000000..942df7a1
--- /dev/null
+++ b/tests/fixtures/crash/349-empty-data-uri.svg
@@ -0,0 +1 @@
+<image xlink:href="data:"


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