[redland-dev] Model serialization bug

Dave Beckett dave.beckett at bristol.ac.uk
Tue Jan 4 09:38:52 PST 2005


On Tue, 4 Jan 2005 10:06:07 -0500
Christopher Schmidt <crschmidt at crschmidt.net> wrote:

> When running the following script:
> 
> import RDF
> p = RDF.Parser()
> m = RDF.Model()
> p.parse_into_model(m, RDF.Uri("http://crschmidt.net/foaf.rdf"))
> print m
> 
> I get a malloc/free error:
> 
> rdf_uri.c:201: (librdf_new_uri_from_uri) assertion failed: object 
> pointer of type librdf_uri is NULL.
> *** glibc detected *** double free or corruption (fasttop): 0x081ceb80
> *** Aborted

I get a slightly different crash (probably because I'm using CVS
redland) which I've hunted down.

There are two problems - firstly, it doesn't handle serializing
with a null base URI properly, so 'print m' isn't going to work.

This can be fixed in python:

print m.to_string(base_uri=RDF.Uri("http://example.org/base#"));

and I'll look at fixing that properly shortly.

The other thing is a bug in raptor trying to make relative URIs for
things that it didn't anticipate - URIs with no path.  I've made a
patch to raptor_uri.c, attached.  Try that out.  (You could
try the test first: make raptor_uri_test; ./raptor_uri_test )

Dave
-------------- next part --------------
Index: raptor_uri.c
===================================================================
RCS file: /usr/local/cvsroot/redland/raptor/raptor_uri.c,v
retrieving revision 1.79
retrieving revision 1.81
diff -c -r1.79 -r1.81
--- raptor_uri.c	3 Jan 2005 19:33:25 -0000	1.79
+++ raptor_uri.c	4 Jan 2005 17:31:49 -0000	1.81
@@ -2,7 +2,7 @@
  *
  * raptor_uri.c - Raptor URI resolving implementation
  *
- * $Id: raptor_uri.c,v 1.79 2005/01/03 19:33:25 cmdjb Exp $
+ * $Id: raptor_uri.c,v 1.81 2005/01/04 17:31:49 cmdjb Exp $
  *
  * Copyright (C) 2002-2004, David Beckett http://purl.org/net/dajobe/
  * Institute for Learning and Research Technology http://www.ilrt.bristol.ac.uk/
@@ -937,12 +937,17 @@
   if(!strncmp((const char*)base_detail->buffer,
               (const char*)reference_detail->buffer, prefix_len)) {
     
+    if(!base_detail->path)
+      goto buildresult;
+    
     /* Find the file name components */
     base_file = (const unsigned char*)strrchr((const char*)base_detail->path, '/');
     if(!base_file)
       goto buildresult;
     base_file++;
-    
+
+    if(!reference_detail->path)
+      goto buildresult;
     reference_file=(const unsigned char*)strrchr((const char*)reference_detail->path, '/');
     if(!reference_file)
       goto buildresult;
@@ -1329,6 +1334,9 @@
   failures += assert_uri_to_relative("http://example.com/base/foo", "http://example.com/base/#foo", ".#foo");
   failures += assert_uri_to_relative("http://example.com/base/foo", "http://example2.com/base/bar", "http://example2.com/base/bar");
   failures += assert_uri_to_relative("http://example.com/base/one?path=/should/be/ignored", "http://example.com/base/two?path=/should/be/ignored", "two?path=/should/be/ignored");
+  failures += assert_uri_to_relative("http://example.org/base#", "http://www.foo.org", "http://www.foo.org");
+  failures += assert_uri_to_relative("http://example.org", "http://a.example.org/", "http://a.example.org/");
+  failures += assert_uri_to_relative("http://example.org", "http://a.example.org", "http://a.example.org");
 
   return failures ;
 }


More information about the redland-dev mailing list