diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 9846185..8c8487a 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1267,13 +1267,10 @@ static GtkCssScanner *
 gtk_css_scanner_new (GtkCssProvider *provider,
                      GtkCssScanner  *parent,
                      GFile          *file,
-                     const gchar    *data,
-                     gsize           length)
+                     const gchar    *data)
 {
   GtkCssScanner *scanner;
 
-  g_assert (data[length] == 0);
-
   scanner = g_slice_new0 (GtkCssScanner);
 
   g_object_ref (provider);
@@ -2443,10 +2440,15 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
             }
         }
     }
+  else
+    {
+      free_data = g_strndup (data, length);
+      data = free_data;
+    }
 
   if (data)
     {
-      scanner = gtk_css_scanner_new (css_provider, parent, file, data, length);
+      scanner = gtk_css_scanner_new (css_provider, parent, file, data);
 
       parse_stylesheet (scanner);
 
