crash with 64k page sizes

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

 



Hi,

So we recently got a bug in rawhide
(https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=202152) where
fontconfig was crashing on a G5 ppc64 box.

It turns out that we've recently switched to using 64k page sizes on
that architecture.  This was causing problems in the
FcCacheMachineSignature() which tries to write the hex encoded page
size into 4 bytes of a buffer.

Behdad suggested a reasonable work around.  Namely, if the page size
won't fit in 4 bytes, extend the page size  one byte to the left into
the empty space before it in the buffer.  This should work because the
string is never parsed.

My patch to do this is attached.

--Ray
--- fontconfig-2.3.95/src/fccache.c.fix-page-size-overflow	2006-08-11 13:34:08.000000000 -0400
+++ fontconfig-2.3.95/src/fccache.c	2006-08-11 13:34:08.000000000 -0400
@@ -39,6 +39,7 @@
 #define MACHINE_SIGNATURE_SIZE (9 + 5*20 + 1)
 /* for when we don't have sysconf: */
 #define FC_HARDCODED_PAGESIZE 8192 
+#define FC_MAX_PAGESIZE 0xfffff
 
 #ifndef O_BINARY
 #define O_BINARY 0
@@ -1536,10 +1537,28 @@
     static char buf[MACHINE_SIGNATURE_SIZE];
     int32_t magic = ENDIAN_TEST;
     char * m = (char *)&magic;
+    long page_size;
 
-    sprintf (buf, "%2x%2x%2x%2x "
+#if defined (HAVE_SYSCONF)
+    page_size = sysconf(_SC_PAGESIZE);
+#else
+    page_size = -1;
+#endif
+
+    if (page_size < 0)
+	    page_size = FC_HARDCODED_PAGESIZE;
+
+    if (page_size > FC_MAX_PAGESIZE)
+    {
+	    page_size = FC_MAX_PAGESIZE;
+	    fprintf (stderr, "system page size is bigger than expected\n");
+    }
+
+    snprintf (buf, 
+	      sizeof (buf),
+	     "%2x%2x%2x%2x "
 	     "%4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x %4x "
-	     "%4x %4x %4x %4x %4x %4x %4x %4x\n", 
+	     "%4x %4x %4x %4x %4x %4x %4x%5x\n", 
 	     m[0], m[1], m[2], m[3],
 	     (unsigned int)sizeof (char),
 	     (unsigned int)sizeof (char *),
@@ -1560,11 +1579,7 @@
 	     (unsigned int)sizeof (FcCharLeaf),
 	     (unsigned int)sizeof (FcChar32),
 	     (unsigned int)sizeof (FcCache),
-#if defined (HAVE_SYSCONF)
-	     (unsigned int)sysconf(_SC_PAGESIZE));
-#else
-	     (unsigned int)FC_HARDCODED_PAGESIZE);
-#endif
+	     (unsigned int)page_size);
 
     return buf;
 }
_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/fontconfig

[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux