On Mon, Jul 08, 2013 at 02:02:25AM -0700, Brandon wrote:
> Olly, I compiled with your patch, and it does not fix the problem. The
> printing program still crashes, but instead it crashes in the function
> wxPostScriptDC::DoDrawText(wxString const&, int, int), line 1220. On
> that line, textbuf is NULL.

Thanks for the feedback.  This is another instance of the same problem,
essentially.  I've fixed that and another instance of the same issue.
The attached patch builds, but I haven't tried to reproduce the problem
yet - if you get a chance to test this updated patch, that'd be great.

A character which can't be represented results in the entire string
it contains getting ignored, which doesn't seem ideal, but it is the
approach upstream suggested, and it's at least a simple non-intrusive
fix.  It beats a crash anyway.

> I also noticed that, in Debian Stable, this problem only occurs if
> libgnomeprint is not installed.

I suspect in that case libgnomeprint will be used instead of the
built-in generic postscript code.

Cheers,
    Olly
diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp
index e2eadde..15e7fd4 100644
--- a/src/generic/dcpsg.cpp
+++ b/src/generic/dcpsg.cpp
@@ -1217,7 +1217,7 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
     PsPrint( "(" );
 
     const wxWX2MBbuf textbuf = text.mb_str();
-    size_t len = strlen(textbuf);
+    size_t len = (wxMBSTRINGCAST textbuf) ? strlen(textbuf) : 0;
     size_t i;
     for (i = 0; i < len; i++)
     {
@@ -1333,7 +1333,7 @@ void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord
 
     PsPrint( "(" );
     const wxWX2MBbuf textbuf = text.mb_str();
-    size_t len = strlen(textbuf);
+    size_t len = (wxMBSTRINGCAST textbuf) ? strlen(textbuf) : 0;
     for (i = 0; i < len; i++)
     {
         int c = (unsigned char) textbuf[i];
@@ -2147,8 +2147,20 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string,
 
     long sum=0;
     float height=fontSize; /* by default */
-    unsigned char *p;
-    for(p=(unsigned char *)wxMBSTRINGCAST strbuf; *p; p++)
+    unsigned char *p=(unsigned char *)wxMBSTRINGCAST strbuf;
+    if(!p)
+    {
+        // String couldn't be converted which used to SEGV as reported here:
+        // http://bugs.debian.org/702378
+        // http://trac.wxwidgets.org/ticket/15300
+        // Upstream suggests "just return if the conversion failed".
+        if (x) (*x) = 0;
+        if (y) (*y) = 0;
+        if (descent) (*descent) = 0;
+        if (externalLeading) (*externalLeading) = 0;
+        return;
+    }
+    for(; *p; p++)
     {
         if(lastWidths[*p]== INT_MIN)
         {

Reply via email to